LC: 1474. Delete N Nodes After M Nodes of a Linked List
1474. Delete N Nodes After M Nodes of a Linked List
Given the head of a linked list and two integers m and n. Traverse the linked list and remove some nodes in the following way:
Start with the head as the current node.
Keep the first
mnodes starting with the current node.Remove the next
nnodesKeep repeating steps 2 and 3 until you reach the end of the list.
Return the head of the modified list after removing the mentioned nodes.
Follow up question: How can you solve this problem by modifying the list in-place?
Example 1:

Example 2:

Example 3:
Example 4:
Constraints:
The given linked list will contain between
1and10^4nodes.The value of each node in the linked list will be in the range
[1, 10^6].1 <= m,n <= 1000
The Essence:
Dieses Problem fordert den Problemlöser heraus, seine Kenntnisse über verkettete Listen, nämlich über den Durchlauf und die Löschung der Knoten, für das Umgehen mit dem Problem anzuwenden.
Details:
Der Problemlöser kann an diesem Beispiel sehen, wie man eine verkettete Liste mit einer while-Schleife und einem Zeiger durchläuft. Es ist ziemlich einfach, einen Knoten in der verketteten Liste zu löschen, indem der Problemlöser einfach den Zeiger des Vorgängerknotens (des aktuellen Knotens, den wir löschen) ändern.
Solution(s):
Default Code:
Last updated