112. Path Sum
https://leetcode.com/problems/path-sum
Python
class Solution:
def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:
return self._travel(0, root, targetSum)
def _travel(self, total: int, node: Optional[TreeNode], targetSum: int) -> bool:
if not node:
return False
if not node.left and not node.right and total + node.val == targetSum:
return True
return self._travel(total+node.val, node.left, targetSum) \
or self._travel(total+node.val, node.right, targetSum)