摘要: Well, a typical backtracking problem. The code is as follows. You may walk through it using the example in the problem statement to see how it works. ... 阅读全文
posted @ 2015-07-11 23:12 jianchao-li 阅读(155) 评论(0) 推荐(0) 编辑
摘要: This problem has a very easy recursive code as follows. 1 class Solution { 2 public: 3 bool hasPathSum(TreeNode* root, int sum) { 4 if (!r... 阅读全文
posted @ 2015-07-11 22:38 jianchao-li 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 /** 4 * @param nums: a vector of integers 5 * @return: an integer 6 */ 7 int findMissing(ve... 阅读全文
posted @ 2015-07-11 21:32 jianchao-li 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for a point. 3 * struct Point { 4 * int x; 5 * int y; 6 * Point() : x(0), y(0) {} 7 * Point(int a, int b) ... 阅读全文
posted @ 2015-07-11 21:28 jianchao-li 阅读(1105) 评论(0) 推荐(0) 编辑
摘要: This problem has a naive idea, which is to traverse all possible pairs of two points and see how many other points fall in the line determined by them... 阅读全文
posted @ 2015-07-11 21:21 jianchao-li 阅读(349) 评论(0) 推荐(0) 编辑
摘要: A simple application of level-order traversal. Just push the last node in each level into the result.The code is as follows. 1 class Solution { 2 publ... 阅读全文
posted @ 2015-07-11 18:12 jianchao-li 阅读(234) 评论(0) 推荐(0) 编辑
摘要: The problem becomes more difficult once the binary tree is not perfect. The idea is still similar to use a level-order traversal. Note that we do not ... 阅读全文
posted @ 2015-07-11 18:00 jianchao-li 阅读(174) 评论(0) 推荐(0) 编辑
摘要: The idea is similar to a level-order traversal and remember to take full advantages of the prefect binary tree assumption in the problem statement.The... 阅读全文
posted @ 2015-07-11 17:00 jianchao-li 阅读(198) 评论(0) 推荐(0) 编辑
摘要: I guess some of you may have noticed that this seemingly simple problem has the lowest acceptance rate among all problems on the LeetCode OJ. Well, so... 阅读全文
posted @ 2015-07-11 14:37 jianchao-li 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Well, remember to take advantage of the property of binary search trees, which is,node -> left -> val val right -> val. Moreover, bothpandqwill be t... 阅读全文
posted @ 2015-07-11 13:50 jianchao-li 阅读(376) 评论(0) 推荐(0) 编辑