66.Binary Tree Preorder Traversal
1.Description(Easy)
Given a binary tree, return the preorder traversal of its nodes' values.
Example
Given:
1
/ \
2 3
/ \
4 5return[1,2,4,5,3].
Can you do it without recursion?
2.Code
Recurision: Divided Conquer && Traversal
Non-recursion:Stack
Divided Conquer:
Traversal:
Non-recursive:
由于stack的特性,先压root, 再压root.right,再压root.left
Last updated
Was this helpful?