can anyone help me with my python code?


  • 0
    W

    I'm not sure why I get 0 from [9], I guess there's something wrong in my code using instance variable, can anyone help explain to me about the errors in my code? Thanks

    '''
    class Solution(object):

    def sumNumbers(self, root):
        if not root:
            return 0
        self.results=0        
        self.pathSum(root,0,self.results)
        return self.results    
    
    def pathSum(self,root,result,results):
        if root:            
            self.pathSum(root.left,result*10+root.val,results)
            self.pathSum(root.right,result*10+root.val,results)
            if not root.left and not root.right:
                results+=result*10+root.val
    

    '''


Log in to reply
 

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