LTOJ
文章平均质量分 63
kyowill
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each原创 2015-09-11 10:41:58 · 272 阅读 · 0 评论 -
Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a原创 2015-10-07 10:32:24 · 312 阅读 · 0 评论 -
First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the原创 2015-10-20 23:27:50 · 333 阅读 · 0 评论 -
Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the ent原创 2015-10-04 10:53:55 · 342 阅读 · 0 评论 -
Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13,原创 2015-10-20 13:56:36 · 356 阅读 · 0 评论 -
Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your原创 2015-10-19 18:31:41 · 317 阅读 · 0 评论 -
Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].class Solution {public: string format(int原创 2015-10-19 14:25:06 · 311 阅读 · 0 评论 -
Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi原创 2015-10-19 12:43:29 · 427 阅读 · 0 评论 -
Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC"原创 2015-09-30 16:45:06 · 399 阅读 · 0 评论 -
Sort List
Sort a linked list in O(n log n) time using constant space complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) :原创 2015-09-14 22:49:35 · 260 阅读 · 0 评论 -
Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2015-10-17 09:09:13 · 395 阅读 · 0 评论 -
Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2015-10-17 14:54:15 · 396 阅读 · 0 评论 -
Permutation总结
分析:求下一个排列,例如:1,2,3,4,51,2,3,5,41,2,4,3,5...1,2,5,4,31,3,2,4,5...大致分三个步骤:(1)从右[len-1]往左[i],找到num[i] > num[i-1],如没有,即i==0,则num为从大到小排列的数组,则此时的下一个排列,为所有元素从小到大的排列;(2)找到[num[i], num[len-转载 2015-09-15 19:22:10 · 421 阅读 · 0 评论 -
Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total numb原创 2015-09-06 16:05:22 · 263 阅读 · 0 评论 -
N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.原创 2015-09-27 20:20:33 · 305 阅读 · 0 评论 -
N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.class Solution {public: bool isValid(vector& svec, int i, in原创 2015-09-27 20:27:14 · 299 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant原创 2015-08-21 14:49:52 · 283 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
AC:用一个vector保存经过以该节点为终点的最大值和以该节点为路径中间点的值int max(int a,int b){ if(a >= b) { return a; }else { return b; }}void dfs(TreeNode* root,vector& vec,int& sum){ if(root == NULL) { return;原创 2015-03-23 12:43:47 · 342 阅读 · 0 评论 -
Insert Interval
ACvector insert(vector &intervals, Interval newInterval) { if(intervals.empty()) { intervals.push_back(newInterval); return intervals; } vector val; for(int i=0;i <原创 2015-03-18 15:22:24 · 441 阅读 · 0 评论 -
WordBreak
AC原创 2015-03-10 22:11:17 · 392 阅读 · 0 评论 -
Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assu原创 2015-09-04 16:26:33 · 289 阅读 · 0 评论 -
Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2015-09-06 09:57:11 · 274 阅读 · 0 评论 -
WordSearch
ACbool dfs(vector > &board,vector > &visit,string word, int i,int j,int dep,int maxdepth){ if(dep>=maxdepth) { return true; } // for(int i=0;i<4;++i) // { if(i+1<board.size()&&board[i+1][原创 2015-03-15 22:21:55 · 482 阅读 · 0 评论 -
Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if t原创 2015-07-09 00:08:55 · 325 阅读 · 0 评论 -
44. Wildcard Matching
Implement wildcard pattern matching with support for ‘?’ and ‘*’.‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence). The matching should cover t原创 2016-03-28 20:54:28 · 662 阅读 · 1 评论 -
160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2016-03-10 16:54:18 · 390 阅读 · 0 评论 -
191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11’ has binary representation 0000000000000原创 2016-03-10 15:42:15 · 334 阅读 · 0 评论 -
71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c” click to show corner cases.Corner Cases: Did you consider the原创 2016-03-30 21:54:12 · 503 阅读 · 0 评论 -
225. Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element. empty() – Return whether原创 2015-12-24 17:26:59 · 422 阅读 · 0 评论 -
232. Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) – Push element x to the back of queue. pop() – Removes the element from in front of queue. peek() – Get the front element. empty()原创 2015-12-23 22:00:14 · 372 阅读 · 0 评论 -
155. Min Stack
Min StackDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top()原创 2015-12-23 16:46:40 · 450 阅读 · 0 评论 -
237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2015-12-23 10:35:37 · 321 阅读 · 0 评论 -
Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's.1 3 3 2 1\ / / / \ \3 2 1 1 3 2/原创 2015-11-02 10:51:07 · 375 阅读 · 0 评论 -
Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.关键思路:最短的含叶子节点子树,考虑如何缓存树的高度/** * D原创 2015-10-31 00:33:47 · 345 阅读 · 0 评论 -
Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2015-10-30 14:39:34 · 392 阅读 · 0 评论 -
Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis原创 2015-08-21 10:13:13 · 307 阅读 · 0 评论 -
Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return原创 2015-10-28 17:44:52 · 441 阅读 · 0 评论 -
Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm should原创 2015-10-29 00:59:32 · 330 阅读 · 0 评论 -
Peeking Iterator
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be retu原创 2015-10-29 00:18:15 · 369 阅读 · 0 评论 -
Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in ea原创 2015-10-29 00:30:56 · 368 阅读 · 0 评论
分享