Clean python Solution

  • 0
    def sumNumbers(self, root):
        :type root: TreeNode
        :rtype: int
        def helper(sum, root):
            if not root:
                return 0   
            sum = sum * 10 + root.val
            if not root.left and not root.right:
                return sum
            return helper(sum, root.left) + helper(sum, root.right)
        return helper(0, root)

Log in to reply

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