# 删除链表倒数第n个节点。假设n大于0 def remove_nth_from_end(head): fast = head count = 0 while fast and count < n: fast = fast._next count += 1 if not fast and count < n: # not that many nodes return head if not fast and count == n: return head._next slow = head while fast._next: fast, slow = fast._next, slow._next slow._next = slow._next._next return head