topic:
Sword finger Offer II 021. Delete the countdown of the linked list n Node.md
Thought:
Double pointer(Sliding window algorithm)。
In this method,We first created a virtual head node dummy,And point it to the original head point head。
Then we use two pointers fast and slow,Will fast Poor movement move forward n step。
Next,We move at the same time fast and slow pointer,until fast pointer到达链表的末尾。
at this time,slow pointer指向倒数第 n+1 Node,我们Will其 next pointer指向 slow.next.next,So as to delete the countdown n Node。
at last,We return virtual head nodes next pointer,It points to delete the countdown n Node后的链表的Head node。
At the beginning, according toCLinked
Code:
1 | class Solution: |
1 | class Solution: |