Given the head of a linked list, remove the nth node from the end of the list and return the head.
Lists are written as arrays: [1, 2, 3] means 1 → 2 → 3.
Examples
Example 1
- Input
- head = [1, 2, 3, 4, 5], n = 2
- Output
- [1, 2, 3, 5]
Example 2
- Input
- head = [1], n = 1
- Output
- []
Example 3
- Input
- head = [1, 2], n = 1
- Output
- [1]
Constraints
- The list has between
1and30nodes. 0 <= Node.val <= 1001 <= n <=the length of the list