思想: Morris traversal.
Solution 1 : Preorder traversal
Solution 2: Inorder traversal.
Solution 3: Morris Traversal.
分类:
其他好文 时间:
2014-08-27 20:25:48
阅读次数:
273
思想: 迭代。
说明: 这类问题,要求一个提供根节点,然后另一个序列(中序序列)可依据根节点分出左右子树。
分类:
其他好文 时间:
2014-08-27 20:20:38
阅读次数:
198
思路: 使用两个队列(一个可以顺序读,所以用vector模拟),每个队列放一层结点。
题解: 两种方法: 1. 使用栈: O(n) Time, O(n) Space。 2. Morris traversal (构造线索树), O(n) Time, O(1) Space.
分类:
其他好文 时间:
2014-08-27 20:16:18
阅读次数:
227
思想: 若递归,传入层号。若迭代,使用队列,在每层结束时,加入一个标记。
思想: 目前用两种方法:1 同上,最后将结果反转一下。 2.先求出最大层数,再层序遍历。(也许还有更好的方法)
分类:
其他好文 时间:
2014-08-27 20:16:08
阅读次数:
212
原题:
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
思路:和上一题一样,后续我们可以通过最后一个值得到根的值,同样可以通过定位根的值得到左右子树的...
分类:
其他好文 时间:
2014-08-21 17:22:24
阅读次数:
138
Follow up for problem "Populating Next Right Pointers in Each Node".
What if the given tree could be any binary tree? Would your previous solution still work?
Note:
You may only use constant extr...
分类:
其他好文 时间:
2014-08-20 22:47:33
阅读次数:
297
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2]....
分类:
其他好文 时间:
2014-08-18 23:29:53
阅读次数:
254
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and ...
分类:
其他好文 时间:
2014-08-17 18:25:02
阅读次数:
233
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:利用先序遍历提供的根节点...
分类:
其他好文 时间:
2014-08-17 16:54:02
阅读次数:
160
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:利用后序遍历提供的根节...
分类:
其他好文 时间:
2014-08-17 16:52:12
阅读次数:
228