leetcood学习笔记-112-路径总和

题目描述:

 

第一次提交:

class Solution(object):
    def hasPathSum(self, root, sum):
        """
        :type root: TreeNode
        :type sum: int
        :rtype: bool
        """
        if not root :
            return False
        if sum - root.val == 0 and not root.left and not root.right:
            return True
        else:
            return self.hasPathSum(root.left,sum-root.val) or self.hasPathSum(root.right,sum-root.val)
        
            

 

posted @ 2019-03-27 15:03  oldby  阅读(123)  评论(0编辑  收藏  举报