Skip to content

Instantly share code, notes, and snippets.

@JasonGideon
Created March 19, 2019 00:05
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/9c1a498cf53f4bff891de2aa465fd86f to your computer and use it in GitHub Desktop.
Save JasonGideon/9c1a498cf53f4bff891de2aa465fd86f 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:
self.res = True
groupint.pop()
else:
findpath(root.left,groupint)
findpath(root.right,groupint)
groupint.pop()
self.res = False
findpath(root,[])
return self.res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment