Why I got a "Exception: Type <type 'instance'>: Not implemented"

  • 1

    The error occurred in Add Two Numbers. Is there anyone who can help me?
    Runtime Error Message: Line 48: Exception: Type <type 'instance'>: Not implemented
    Last executed input: [0], [0]

     # Definition for singly-linked list.
     class ListNode:
         def __init__(self, x):
             self.val = x
             self.next = None
     class Solution:
         # @param {ListNode} l1
         # @param {ListNode} l2
         # @return {ListNode}
         def addTwoNumbers(self, l1, l2):
             ret = ListNode(0)   
             cur = ret           
             while True:
                 if l1:
                     cur.val += l1.val
                     l1 = l1.next
                 if l2:
                     cur.val += l2.val
                     l2 = l2.next
                 carry = cur.val // 10    
                 cur.val %= 10     
                 if l1 or l2 or carry:
                     cur.next = ListNode(carry)
                     cur = cur.next         
             return ret

  • 4

    The system has defined ListNode class for you, remember to comment it out.

  • 1

    You are so brilliant. Thank you very much.

Log in to reply

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