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
Same with add binary. You can also skip delete the result pointer. But just return result->next. Depends on the interviewer. 1 /** 2 * Definition for....
分类:
其他好文 时间:
2015-03-18 07:47:51
阅读次数:
114
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
There are three methods to do it:1. recursive(use memory stack): (Time O(n), Space O(logn) 1 /** 2 * Definition for binary tree 3 * struct TreeNode .....
分类:
其他好文 时间:
2015-03-18 07:46:37
阅读次数:
117