Construct Binary Tree from Inorder and Postorder TraversalGiven inorder and postorder traversal of a tree, construct the binary tree.Note:You may assu...
分类:
其他好文 时间:
2014-11-30 15:20:40
阅读次数:
128
是这题的变种对一棵树从最后一次开始层次遍历,并返回结果。例如:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ ...
分类:
其他好文 时间:
2014-11-29 15:57:28
阅读次数:
251
代码实现:给定一个中序遍历和前序遍历怎么构造出这颗树!(假定数中没有重复的数字)因为没有规定是左小右大的树,所以我们随意画一颗数,来进行判断应该是满足题意的。 3 / \ 2 4 /\ / \1 6 5 7中序遍历:1263547.后序遍历:16257...
分类:
其他好文 时间:
2014-11-29 14:27:53
阅读次数:
111
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree {3...
分类:
其他好文 时间:
2014-11-29 07:06:01
阅读次数:
191
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-11-29 06:47:04
阅读次数:
137
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-11-29 06:40:34
阅读次数:
167
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Solution: 1 /**...
分类:
其他好文 时间:
2014-11-29 01:31:14
阅读次数:
256
给定一个树,按照Z字形记录每一行。例如:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its zigzag level order traversal as:[ [3], [20,9], ...
分类:
其他好文 时间:
2014-11-28 14:18:16
阅读次数:
131
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
这个题目比较简单,借助容器queue即可完成二叉树的层序遍历。我的C++实现代码如下:
vector > levelOrder(TreeNode *...
分类:
其他好文 时间:
2014-11-28 10:22:22
阅读次数:
206
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
这个简单的问题可以这样解决:利用LeetCode[Tree]: Binary Tree Level...
分类:
其他好文 时间:
2014-11-28 10:15:15
阅读次数:
227