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:
Solution:
这是简单的DFS的遍历题目,由于需要不停的传递进入str变量,这个时候有两种做法,一种就是默认根节点有值,然后-> 指向子节点,另外一种就是我地下的做法。
Last updated
Was this helpful?