Path Sum
Solution Code
class Solution:
def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:
if not root:
return False
if not root.left and not root.right:
return root.val == targetSum
remaining = targetSum - root.val
return (self.hasPathSum(root.left, remaining) or
self.hasPathSum(root.right, remaining))Time Complexity
O(N)
Space Complexity
O(H)

