Binary Tree Inorder TraversalGiven a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ ...
分类:
其他好文 时间:
2014-08-31 18:27:01
阅读次数:
168
思想: 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
原题:
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
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 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
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree. 1 class Solut...
分类:
其他好文 时间:
2014-08-17 01:03:21
阅读次数:
199
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-16 23:48:31
阅读次数:
333