Verify Preorder Serialization of a Binary Tree
Total Accepted: 14360 Total
Submissions: 44550 Difficulty: Medium
One way to serialize a binary tree is to use pre-order traver...
分类:
其他好文 时间:
2016-06-16 10:33:53
阅读次数:
356
这个我以前写过好几次了……把以前的粘上来吧 先序遍历的第一个数就是树的根,然后在中序遍历里面找到这个根的位置,它左边的就是左子树,右边的就是右子树,例如: 如果一个树的先序遍历结果是1245,中3687序是42516837。 那么它的跟就是1,用1把中序分成两半,左子树就是425,长度为3,右子树就 ...
分类:
其他好文 时间:
2016-06-10 06:15:25
阅读次数:
187
题目链接:https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/
题目:
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we rec...
分类:
其他好文 时间:
2016-05-30 15:14:14
阅读次数:
138
树的先序遍历。定义一个栈,先压入中间结点并访问,然后依次压入右、左结点并访问。 vector<int> preorderTraversal(TreeNode *root) { vector<int> result; stack<TreeNode *>s; TreeNode *p; p = root; ...
分类:
其他好文 时间:
2016-05-28 16:00:27
阅读次数:
138
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. ...
分类:
其他好文 时间:
2016-05-22 22:47:58
阅读次数:
161
题目链接:https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
题目:
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may ass...
分类:
其他好文 时间:
2016-05-22 12:25:16
阅读次数:
160