Skip to content
Onsite

Delete at Specific Position

EasyP3Coding

Given the head of a singly linked list and a 0-based position, delete the node at that position and return the head of the resulting list. A list node has val and next. The ListNode class is already defined for you.

position is always a valid index of an existing node.

Example 1

Input
head = [1,2,3,4], position = 2
Output
[1,2,4]

Example 2

Input
head = [9,8], position = 0
Output
[8]

Example 3

Input
head = [5], position = 0
Output
[]

Constraints

  • 1 <= number of nodes <= 1000
  • 0 <= position < number of nodes
  • -10^4 <= Node.val <= 10^4

Hints

Run checks the 3 visible tests, Submit all 9.