摘要:
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. ... 阅读全文
摘要:
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... 阅读全文
摘要:
1 class Solution { 2 public: 3 /** 4 * @param nums: a vector of integers 5 * @return: an integer 6 */ 7 int findMissing(ve... 阅读全文
摘要:
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) ... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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 ... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
Well, remember to take advantage of the property of binary search trees, which is,node -> left -> val val right -> val. Moreover, bothpandqwill be t... 阅读全文