Remove Nth Node From End of List
Given the head of a linked list, remove the nth node from the end of the list and return the head of the modified list.
Example 1
[1] -> [2] -> [3] -> [4] -> [5] -> null --- [1] -> [2] -> [3] -> [5] -> null
Input
head = [1,2,3,4,5], n = 2Output
[1,2,3,5]The 2nd node from the end is the node with value 4, so it is removed.
Example 2
[1] -> null --- null
Input
head = [1], n = 1Output
[]The only node is also the 1st node from the end, so removing it leaves an empty list.
Constraints
- The number of nodes in the list is sz
- 1 <= sz <= 30
- 0 <= Node.val <= 100
- 1 <= n <= sz