天天看點

LeetCode--Binary Tree Preorder Traversal

 Total Accepted: 18022 Total

Submissions: 51784

Given a binary tree, return the preorder traversal of its nodes‘ values.

For example:

Given binary tree <code>{1,#,2,3}</code>,

return <code>[1,2,3]</code>.

Note: Recursive solution is trivial, could you do it iteratively?

 法一,遞歸