1class Solution(object):2def hasPathSum(self, root, targetSum):3"""4:type root: TreeNode5:type targetSum: int6:rtype: bool7"""8if not root:9return False10targetSum -= root.val11if not root.left and not root.right:12return not targetSum13return self.hasPathSum(root.left, targetSum) or self.hasPathSum(14root.right, targetSum15)