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-07-10 09:58:40
阅读次数:
224
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.方法:在inorder中寻找...
分类:
其他好文 时间:
2014-07-07 23:18:53
阅读次数:
283
二叉树的前序遍历:root点先被访问,然后是left和right子节点。迭代的版本也相对好写。1、递归版本:时间复杂度O(N),空间复杂度O(N) 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int va...
分类:
其他好文 时间:
2014-07-07 20:35:24
阅读次数:
158
二叉树的中序遍历1、递归版本/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) :...
分类:
其他好文 时间:
2014-07-07 20:00:20
阅读次数:
161
二叉树的后续遍历1、递归版本/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) :...
分类:
其他好文 时间:
2014-06-30 14:17:28
阅读次数:
306
题目:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3]....
分类:
其他好文 时间:
2014-06-26 16:03:52
阅读次数:
296
题目:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].N...
分类:
其他好文 时间:
2014-06-26 16:02:42
阅读次数:
172
题目:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1]...
分类:
其他好文 时间:
2014-06-26 15:59:16
阅读次数:
207
Given a binary tree, return the postorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [3,2,1].
Note: Recursive solut...
分类:
其他好文 时间:
2014-06-22 20:58:01
阅读次数:
157
Given a binary tree, return the preorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,2,3].
Note: Recursive soluti...
分类:
其他好文 时间:
2014-06-22 16:37:51
阅读次数:
168