###112. Path Sum
题目: https://leetcode.com/problems/path-sum/
难度:
Easy
递归
class Solution(object):
def hasPathSum(self, root, sum):
"""
:type root: TreeNode
:type sum: int
:rtype: bool
"""
if root == None:
return False
else:
if root.val == sum and (root.left == None and root.right == None):
return True
else:
return self.hasPathSum(root.left, sum - root.val) or self.hasPathSum(root.right, sum - root.val)