Skip to content

Commit

Permalink
不知道变量范围是怎么规定的。改用返回值了。
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Dec 11, 2018
1 parent eb555c5 commit 6403635
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions Path Sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@ def hasPathSum(self, root, sum):

def dfs(root, tar):
if not root:
return
return False
if root.val == tar and root.left is None and root.right is None:
global res
res = True
# print(23, res)
return
dfs(root.left, tar - root.val)
dfs(root.right, tar - root.val)
return True
return dfs(root.left, tar - root.val) or dfs(root.right, tar - root.val)

if not root:
return False
res = False
dfs(root, sum)
return res
return dfs(root, sum)


root = TreeNode(5)
Expand Down

0 comments on commit 6403635

Please sign in to comment.