class Solution(object):
def hasPathSum(self, root, targetSum):
if root == None:
return False
if root.left == None and root.right == None:
return root.val == targetSum
return self.hasPathSum(root.right, targetSum - root.val) or self.hasPathSum(root.left, targetSum - root.val)
网友评论