Recursive method can be unstand easily:1. Assume we get the sub node with this transition. So we need to make the current node.2. As the symmetic, the...
分类:
其他好文 时间:
2015-03-18 10:12:06
阅读次数:
128
Basic question. Use a queue to store Node, use two numbers to record current level node numbers and next level node numbers. 1 /** 2 * Definition for....
分类:
其他好文 时间:
2015-03-18 08:58:27
阅读次数:
105
Same with inorder.1. recursive: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeN...
分类:
其他好文 时间:
2015-03-18 08:58:05
阅读次数:
131
Still 3 methods:Same with inorder, but post order is a little different. We need to treat it as reverse result of preorder.So we go to right branch fi...
分类:
其他好文 时间:
2015-03-18 08:57:58
阅读次数:
132
This question is almost same as the previous one.I just use a stack (another vector) of vector to store the level result. Then reverse it. 1 /** 2 * ....
分类:
其他好文 时间:
2015-03-18 08:56:41
阅读次数:
155
Use lMax get the maximum value of a sub SINGLE branch (left branch or right branch or just current node).Use gMax get the maximum value of the whole s...
分类:
其他好文 时间:
2015-03-18 08:56:01
阅读次数:
190
It is similar to use stack for BST inorder traversal.So do the same thing :1. Get stack to store right branchs(include current node).2. When you pop t...
分类:
其他好文 时间:
2015-03-18 07:50:34
阅读次数:
139
Need a helper function to return the binary tree maximum height. If the return value is -1, it means there is a imbalanced subbranch . 1 /** 2 * Defi....
分类:
其他好文 时间:
2015-03-18 07:47:44
阅读次数:
123
Use a hash table to record it. The tricky part is that when the hash value is > 0, it is the index + 1. Otherwise, that string already exists in resul...
分类:
其他好文 时间:
2015-03-18 07:47:38
阅读次数:
100
This is simple, use greedy algorithm will solve the problem. 1 class Solution { 2 public: 3 int maxProfit(vector &prices) { 4 int len = pr...
分类:
其他好文 时间:
2015-03-18 07:46:55
阅读次数:
155