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?
2252
4036
2万+
1万+
715

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