My simple accepted python solution


  • 1
    V
    class Solution:
        # @param root, a tree node
        # @return an integer
        def sumNumbers(self, root,count=0):
            if root is None:
                return 0
            count = 10*count + root.val
            if root.left is None and root.right is None: 
                return count
            return self.sumNumbers(root.left,count)+self.sumNumbers(root.right,count)

Log in to reply
 

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