Skip to content

Instantly share code, notes, and snippets.

@JasonGideon
Created March 19, 2019 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JasonGideon/1667faf09154a35ae0fd7deae6da8646 to your computer and use it in GitHub Desktop.
Save JasonGideon/1667faf09154a35ae0fd7deae6da8646 to your computer and use it in GitHub Desktop.
class Solution:
def hasPathSum(self, root: TreeNode, suma: int) -> bool:
def findpath(root,groupint):
if root:
groupint.append(root.val)
if not root.right and not root.left:
if sum(groupint) == suma:
print('check')<----print 了两次,说明第一次并没有 return True 出 method
return True <----请问这里为什么 return 不出去?
groupint.pop()
else:
findpath(root.left,groupint)
findpath(root.right,groupint)
groupint.pop()
return findpath(root,groupint) <----返回的是 NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment