Given the head of a linked list, remove the nᵗʰ node from the end of the list and return its head. Example: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Explanation: The 2nd node from end (value 4) is removed. Pattern focus: Two-pointer gap (use dummy head to handle edge cases).
head = ListNode, n = int
return ListNode
Example 1:
Input:
head = [1,2,3,4,5] n = 2
Output:
[1,2,3,5]
Explanation:
Remove the 2nd node from end (4).
Example 2:
Input:
head = [1] n = 1
Output:
null
Explanation:
List has one node, remove it to get empty list.