2019-01-26 08:34:45 +08:00

10 lines
259 B
Python

def removeNthFromEnd(self, head, n):
slow = fast = head
for i in range(n):
fast = fast.next
if not fast: return head.next
while fast.next:
fast = fast.next
slow = slow.next
slow.next = slow.next.next
return head