[LeetCode]257. Binary Tree Paths
257. Binary Tree Paths
class Solution(object):
def binaryTreePaths(self, root):
"""
:type root: TreeNode
:rtype: List[str]
"""
def helper(node, path):
if not node.left and not node.right:
res.append(path)
return
print path
if node.left:
helper(node.left, path + '->' + str(node.left.val))
if node.right:
helper(node.right, path + '->' + str(node.right.val))
if not root:
return []
res = []
helper(root, str(root.val))
return res
关注公众号:数据结构与算法那些事儿,每天一篇数据结构与算法