Be care when Using python

  • 0

    Be care, everyone who use python to solve this prob !
    Do not define your own class to describe the List Node, otherwise, U will get RE!
    Keep it simple, just as a simple follow:


    class Solution:

    def addTwoNumbers(self, l1, l2):
        d = 0
        LNode = ListNode(0)
        head = LNode
        while d or l1 or l2:
            tmp = ListNode(d)
            if l1:
                tmp.val += l1.val
                l1 =
            if l2:
                tmp.val += l2.val
                l2 =
            d = tmp.val // 10
            tmp.val %= 10
  , head = tmp, tmp


Log in to reply

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