{leetcode}/problems/binary-tree-preorder-traversal/[LeetCode - Binary Tree Preorder Traversal^]
Given a binary tree, return the preorder traversal of its nodes' values.
Example:
Input:[1,null,2,3]
1 \ 2 / 3 Output:[1,2,3]
Follow up: Recursive solution is trivial, could you do it iteratively?
凡是用递归能解决的问题,都可以使用遍历来解决。用递归来求解问题,无非就是使用了方法栈来保存相关信息。同样,可以使用 Stack
来自己动手维护这些信息。
link:{sourcedir}/_0144_BinaryTreePreorderTraversal.java[role=include]
link:{sourcedir}/_0144_BinaryTreePreorderTraversal_Recur.java[role=include]
- 一刷
-
link:{sourcedir}/_0144_BinaryTreePreorderTraversal.java[role=include]
- 二刷
-
link:{sourcedir}/_0144_BinaryTreePreorderTraversal_Recur.java[role=include]
- 二刷(Morris遍历)
-
link:{sourcedir}/_0144_BinaryTreePreorderTraversal_Morris.java[role=include]