Description
Given the head of a linked list, remove the nth node from the end and return the modified list as an array of node values.
Examples
Input:
head = [1,2,3,4,5], n = 2Output:
[1,2,3,5]Explanation:
Remove 4, which is 2nd from end.
Input:
head = [1], n = 1Output:
[]Explanation:
Edge case with empty result.
Input:
head = [7,8,9], n = 3Output:
[8,9]Explanation:
Remove 7, which is 3rd from end (the first node). This demonstrates removing the head node from a multi-element list.
Constraints
- •
1 ≤ list length ≤ 30 - •
1 ≤ n ≤ list length