class Solution(object):
def binaryTreePaths(self, root):
"""
:type root: TreeNode
:rtype: List[str]
"""
self.ans=[]
self.list=[]
def rec(root):
if not root:
return 0
self.list.append(str(root.val))
rec(root.left)
rec(root.right)
if not root.left and not root.right:
self.ans.append('->'.join(self.list))
self.list.pop()
return 0
rec(root)
return self.ans
leetcode257. 二叉树的所有路径
最新推荐文章于 2024-08-20 10:48:49 发布