Dodomeki
Sign in

67. Remove Nth Node from End

Medium

You are given a linked list and a valid integer n. Remove the n-th node counted from the end and return the head of the resulting list. Consider the last node to be position 1.

Example 1
Input: head = [5, 8, 2, 9], n = 2
Output: [5, 8, 9]
Example 2
Input: head = [7], n = 1
Output: []
Constraints
  • 1 <= n <= tamanho da lista
  • 0 <= tamanho da lista <= 10000.
Linked listTwo pointers
Caso 1
head =
[5,8,2,9]
n =
2
Expected =
[5,8,9]
Caso 2
head =
[7]
n =
1
Expected =
[]

Run checks these 2 cases. Submit runs all 6, including hidden ones.