Question
Given a binary tree, return the preorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
return [1,2,3].
Explanation
依旧是两种方法,递归和遍历。递归非常容易,分治即可。遍历需要用到Stack这个数据结构,想清楚顺序就好。
Given a binary tree, return the preorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
return [1,2,3].
依旧是两种方法,递归和遍历。递归非常容易,分治即可。遍历需要用到Stack这个数据结构,想清楚顺序就好。