MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / hasPathSum

Method hasPathSum

leetcode/112. Path Sum.py:23–28  ·  view source on GitHub ↗
(self, root, sum)

Source from the content-addressed store, hash-verified

21
22class Solution(object):
23 def hasPathSum(self, root, sum):
24 if not root:
25 return False
26 if root.val == sum and root.left is None and root.right is None:
27 return True
28 return self.hasPathSum(root.left, sum-root.val) or self.hasPathSum(root.right, sum-root.val)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected