1474. Delete N Nodes After M Nodes of a Linked List
1474. Delete N Nodes After M Nodes of a Linked List
Description
You are 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
m
nodes starting with the current node. - Remove the next
n
nodes - Keep 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.
Example 1:

1 | Input: head = [1,2,3,4,5,6,7,8,9,10,11,12,13], m = 2, n = 3 |
Example 2:

1 | Input: head = [1,2,3,4,5,6,7,8,9,10,11], m = 1, n = 3 |
Constraints:
- The number of nodes in the list is in the range
[1, 10^4]
. 1 <= Node.val <= 10^6
1 <= m, n <= 1000
Follow up: Could you solve this problem by modifying the list in-place?
Hints/Notes
- 2025/05/09 Q1
- linked list
- Leetcode solution
Solution
Language: C++
1 | /** |