美文网首页
leetcode 112

leetcode 112

作者: 七齐起器 | 来源:发表于2021-02-27 18:23 被阅读0次

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)

相关文章

网友评论

      本文标题:leetcode 112

      本文链接:https://www.haomeiwen.com/subject/hqtefltx.html