思路:将p入栈并访问p.val,遍历左子树;遍历完左子树返回时,栈顶元素应为p,出栈,再先序遍历p的右子树。代码:/** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * ...
分类:
其他好文 时间:
2015-12-30 00:23:06
阅读次数:
212
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].
题目要求对二叉树进行非递归的中序遍历,所谓前序遍历即,先访问左子树、再访问根节点、然...
分类:
其他好文 时间:
2015-06-01 22:47:56
阅读次数:
137
Given a binary tree, return the preorder traversal of its nodes’ values.For example:
Given binary tree {1,#,2,3},1
\
2
/
3return [1,2,3].Note: Recursive solution is trivial, could...
分类:
其他好文 时间:
2015-06-01 22:47:38
阅读次数:
128
problem:
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: Re...
分类:
其他好文 时间:
2015-05-05 10:36:19
阅读次数:
126