Simple Python Solution 3 lines

  • 4
    def hasPathSum(self, root, sum):
            if root == None:return False
            if root.val - sum == 0 and root.left == None and root.right == None:return True
            return self.hasPathSum(root.left, sum-root.val) or self.hasPathSum(root.right, sum-root.val)

  • 0

    very clean code

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.