Python, dummy head simplify the problem

  • 1

    Use a dummy so not to worry if n is 1 or the length of the linked list..

    def removeNthFromEnd(self, head, n):
        dummy = l = ListNode(0) = r = head
        for _ in range(n):
            r =
        while r:
            l, r =, =

Log in to reply

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