Python error " ListNode instance has no attribute '__len__'" with input [1],1


  • 0
    Z

    Hi all,

    I have this question about this problem. here is my code:

    class Solution:
        # @param {ListNode} head
        # @param {integer} n
        # @return {ListNode}
        def removeNthFromEnd(self, head, n):
            self.head = head
            self.n = n
            if len(head) == 0:
                return head
            if n > len(head):
                return head
            if n == 0:
                return head
            n = 0-n
            del head[n]
            return head
    

    I really don't understand this "listnode" error.
    Please help me, thanks


Log in to reply
 

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