#Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


def hasPathSum(self, root, targetSum):
    if (not root):
        return False
    elif ((not root.left) and (not root.right) and (targetSum - root.val == 0)):
        return True
    else:
        return ((self.hasPathSum(root.left, targetSum - root.val)) or (
            self.hasPathSum(root.right, targetSum - root.val)))
