您的位置:首页 > 其它

Path Sum

2016-05-27 18:47 148 查看
# Definition for a  binary tree node
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
# @param root, a tree node
# @param sum, an integer
# @return a boolean
def hasPathSum(self, root, sum):
ret = False
if root == None:
return ret
sum -= root.val
if sum==0 and root.left==None and root.right==None:
ret = True
return ret or self.hasPathSum(root.left,sum) or self.hasPathSum(root.right,sum)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: