Skip to content

Commit

Permalink
2020-01-19
Browse files Browse the repository at this point in the history
  • Loading branch information
JiayangWu committed Jan 20, 2020
1 parent efa1a32 commit 67b55f2
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions 0257.二叉树的所有路径/0257-二叉树的所有路径.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ def binaryTreePaths(self, root):
:rtype: List[str]
"""
if not root:
return []
if not root.left and not root.right:
return [str(root.val)]
return []
self.res = []

def dfs(node, tmp):
if not node:
return
if not node.left and not node.right:
self.res.append(tmp + "->" + str(node.val))
dfs(node.left, tmp + "->" + str(node.val))
dfs(node.right, tmp + "->" + str(node.val))

dfs(root.left, str(root.val))
dfs(root.right, str(root.val))
return self.res
if not node:
return
if not node.left and not node.right:
self.res.append(tmp + str(node.val))
return

dfs(node.left, tmp + str(node.val) + "->")
dfs(node.right, tmp + str(node.val) + "->")

dfs(root, "")
return self.res

0 comments on commit 67b55f2

Please sign in to comment.