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?
思路:
递归or循环
1、递归:按照根左右的顺序访问二叉树、即root、left、right
2、循环:用栈来转换、这里是right节点需要保存、left节点需要一直遍历下去、
所以先保存right节点、再保存left节点、正好和递归的顺序反了过来