My Python Solution


  • 0
    V
    class Solution:
    curNode=None
    plus=0
    # @return a ListNode
    def addTwoNumbers(self, l1, l2):
        self.calc(l1,l2)      
        return self.curNode
    
    def calc(self,note1,note2):
        if not note2:
            note2=ListNode(0)
        if not note1:
            note1=ListNode(0)
        val=note1.val+note2.val+self.plus
        if(val>=10):
            val=abs(10-val)
            if note1.next or note2.next:
                self.plus=1
            else:
                self.curNode=ListNode(1)     
        else:
            self.plus=0                 
                    
        if note1.next or note2.next:
            self.calc(note1.next,note2.next)
        newNode=ListNode(val)
        newNode.next=self.curNode
        self.curNode=newNode

  • 0
    P

    incorrect solution


Log in to reply
 

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