120. Snip From the End
mediumlinked listtwo pointers
Remove the n-th node from the end of the list and return its head. Try to do it in one pass.
The list arrives as a ListNode (val, next). Tests show lists as arrays.
Example 1
Inputhead = [1,2,3,4,5], n = 2
Output[1,2,3,5]
Example 2
Inputhead = [1], n = 1
Output[]
Example 3
Inputhead = [1,2], n = 1
Output[1]
Constraints
- 1 ≤ n ≤ length ≤ 30