You are given the beginning of a linked list head, and an integer n.
Remove the nth node from the end of the list and return the beginning of the list.
Examples
Example 1
Input: head = [1,2,3,4], n = 2
Output: [1,2,4]
Example 2
Input: head = [5], n = 1
Output: []
Example 3
Input: head = [1,2], n = 2
Output: [2]
Constraints
- The number of nodes in the list is
sz 1 <= sz <= 300 <= Node.val <= 1001 <= n <= sz
How the tests work: lists are written as arrays —
[1,2,3]is the chain1 → 2 → 3. Your function receives realListNodeobjects, and the list you return is read back into an array.