257 Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.
For example, given the following binary tree:
|
|
All root-to-leaf paths are:
|
|
思路
利用深度优先遍历,可以得到树从根节点到叶子节点的所有路径。递归直到访问到叶子节点,此时向结果数组加入一个路径的字符串。
|
|
Given a binary tree, return all root-to-leaf paths.
For example, given the following binary tree:
|
|
All root-to-leaf paths are:
|
|
利用深度优先遍历,可以得到树从根节点到叶子节点的所有路径。递归直到访问到叶子节点,此时向结果数组加入一个路径的字符串。
|
|