Python sol( recursive with list)


#1

class Solution:
# @param A : root node of tree

@return an integer

def sumNumbers(self, A):
    self.sum=0
    lst=[]
    if A==None:
        return 0
    self.pre(A,lst)
    return self.sum%1003
def pre(self,A,lst):
    lst.append(A.val)
    if A.left==None and A.right==None:
        self.sum+=int(''.join(list(map(str,lst))))
    if A.left!=None:
        self.pre(A.left,lst)
    if A.right!=None:
        self.pre(A.right,lst)
    lst.pop().