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 solution is trivial, could you do it iteratively?
本文介绍二叉树前序遍历的两种非递归实现方法:使用栈模拟递归调用及Morris线索化遍历。前者利用栈进行节点出入栈操作,后者通过对节点的巧妙处理实现高效遍历。
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 solution is trivial, could you do it iteratively?
758

被折叠的 条评论
为什么被折叠?