It is similar to use stack for BST inorder traversal.So do the same thing :1. Get stack to store right branchs(include current node).2. When you pop t...
分类:
其他好文 时间:
2015-03-18 07:50:34
阅读次数:
139
There are three methods to do it:1. recursive(use memory stack): (Time O(n), Space O(logn) 1 /** 2 * Definition for binary tree 3 * struct TreeNode .....
分类:
其他好文 时间:
2015-03-18 07:46:37
阅读次数:
117
Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note...
分类:
编程语言 时间:
2015-03-18 01:04:11
阅读次数:
209
2.思路
a.先遍历左子树直至左孩子为空
b.然后看当前节点的右子树是否为空,为空,则访问当前节点,弹出当前节点,重新判断;不为空,访问当前节点,然后将当前节点弹出,并将当前节点的右孩子进栈,返回a
c.这中间需要注意的是,在弹出当前节点后,在获得栈顶的当前节点前先判断下栈是否为空...
分类:
其他好文 时间:
2015-03-16 21:19:34
阅读次数:
118
Given a binary tree, return theinordertraversal of its nodes' values.和preorder是一样的,把左子节点一直压入到栈中,直到没有左子节点为止,然后出栈访问,存储右子节点。 1 vector inorderTraversal(Tr...
分类:
其他好文 时间:
2015-03-15 00:42:02
阅读次数:
111
二叉树的中序遍历,没啥好说的/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) :...
分类:
其他好文 时间:
2015-03-14 16:41:54
阅读次数:
126
Construct Binary Tree from Preorder and Inorder Traversal问题:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may ass...
分类:
其他好文 时间:
2015-03-14 13:43:43
阅读次数:
121
Construct Binary Tree from Inorder and Postorder Traversal问题: Given inorder and postorder traversal of a tree, construct the binary tree.思路: dfs我的代码.....
分类:
其他好文 时间:
2015-03-13 22:11:25
阅读次数:
198
欢迎大家阅读参考,如有错误或疑问请留言纠正,谢谢
94 Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
\...
分类:
其他好文 时间:
2015-03-12 09:54:04
阅读次数:
121
标题:Construct Binary Tree from Preorder and Inorder Traversal通过率:26.5难度: 中等Given preorder and inorder traversal of a tree, construct the binary tree.No...
分类:
其他好文 时间:
2015-03-11 23:14:51
阅读次数:
153