Why my code get an “Exception: Type <class '__main__.ListNode'>: Not implemented”?


  • 1
    J

    class ListNode(object):

    def __init__(self, x):
    
        self.val = x
        self.next = None
    

    class Solution(object):

    def addTwoNumbers(self, l1, l2):
    
        R = L = ListNode(0)
        flag = False
        while True:
            if not l1 or l2:
                sumVal = flag + l1.val + l2.val
                l1 = l1.next
                l2 = l2.next
            if l1 and not l2:
                sumVal = flag + l1.val
                l1 = l1.next
            if l2 and not l1:
                sumVal = flag + l2.val
                l2 = l2.next
            else: break
            if sumVal > 10:
                flag = True
            else:
                flag = False
            L.val = sumVal % 10
            L.next = ListNode(0)
            L = L.next
        return R

Log in to reply
 

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