Remove Nth Node From End
Problem statement
Remove the n-th node from the end of the singly linked list and return its head.
Function
removeNthFromEnd(head: ListNode, n: int) → ListNodeExamples
Example 1
head = [1,2,3,4,5]n = 2return = [1,2,3,5]The value 4 is second from the end.
Constraints
- The list contains between 1 and
10^5nodes. 1 <= n <= list length.