One Pass Python Solution

  • 1
    # Definition for singly-linked list.
    # class ListNode(object):
    #     def __init__(self, x):
    #         self.val = x
    # = None
    class Solution(object):
        def removeNthFromEnd(self, head, n):
            :type head: ListNode
            :type n: int
            :rtype: ListNode
            faster, flag = head, True
            for i in range(0,n):
                faster =
            while faster:
                if flag:
                    slower, flag = head, False
                    slower =
                faster =
            if flag:
                head =
       = None if not else
            return head

Log in to reply

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