Description
Given the head of a linked list, remove the nth node from the end of the list and return its head. You should do this in one pass through the list.
Examples
Input:
head = [1,2,3,4,5], n = 2Output:
[1,2,3,5]Explanation:
Remove the 2nd node from the end (4).
Input:
head = [1], n = 1Output:
[]Explanation:
Remove the only node.
Input:
head = [1,2,3], n = 3Output:
[2,3]Explanation:
Remove the 3rd node from the end, which is the first node (1). This demonstrates removing the head node from a multi-node list.
Constraints
- •
The number of nodes in the list is sz. - •
1 ≤ sz ≤ 30 - •
1 ≤ n ≤ sz