摘要: We set two pointers number1 and number2 to record the most probably element of which the amount is over 1/3. Meanwhile, we have count1 to record the t 阅读全文
posted @ 2016-06-09 04:11 爱推理的骑士 阅读(120) 评论(0) 推荐(0) 编辑
摘要: Note that when you put the list to be the parameter, and each time you do the recursion, you add element into the list, you need to remove the former 阅读全文
posted @ 2016-03-01 05:23 爱推理的骑士 阅读(158) 评论(0) 推荐(0) 编辑
摘要: We can use the idea of quichsort to solve this problem. First we set a pivot; which we let the first element of current array to be pivot; we set star 阅读全文
posted @ 2016-03-01 03:25 爱推理的骑士 阅读(141) 评论(0) 推荐(0) 编辑
摘要: In this problem, house are arranged in a circle, robber should not invade into two adjacent houses. Compared to the former problem, we need to conside 阅读全文
posted @ 2016-02-29 08:21 爱推理的骑士 阅读(158) 评论(0) 推荐(0) 编辑
摘要: We can use bfs to solve this problem; By traverse the prerequisites array, we can generate two graph representations. One is an array of list of out n 阅读全文
posted @ 2016-02-23 07:31 爱推理的骑士 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Use two pointer to find the minimum subarray size; At first, we find the shortest subarray from the first element of which the sum is greater than or 阅读全文
posted @ 2016-02-23 04:58 爱推理的骑士 阅读(137) 评论(0) 推荐(0) 编辑
摘要: Suppose n is the number of list, then the runtime is O(n^2/2), space is O(n) We create an integer array of size n, which is also the number of digits 阅读全文
posted @ 2016-01-31 12:39 爱推理的骑士 阅读(156) 评论(0) 推荐(0) 编辑
摘要: In this problem, we cannot find an efficient recursion way to set up the next pointer. For example, we can do like this, in this way we may set up too 阅读全文
posted @ 2016-01-31 10:52 爱推理的骑士 阅读(131) 评论(0) 推荐(0) 编辑
摘要: Using DFS to traverse the tree. 4 cases for each node in the tree: case 1: it's a leaf node, set a pointer pointing to the node. We're reaching an end 阅读全文
posted @ 2016-01-30 06:55 爱推理的骑士 阅读(183) 评论(0) 推荐(0) 编辑
摘要: We use DFS to traverse the tree. For each node through the path, let sum = sum - node.val. When we look through a node, create a List<List<Integer>> t 阅读全文
posted @ 2016-01-29 14:21 爱推理的骑士 阅读(129) 评论(0) 推荐(0) 编辑