Skip to content

Practice Delete Node in a Linked List

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#237
LeetCode Problem

Delete Node in a Linked List

Problem Statement

You receive a reference to a node in a singly linked list, but not the head of the list. All values are distinct, and the given node is guaranteed not to be the tail. Delete its value from the list: the resulting list must have one fewer node, and the values before and after the removed value must keep their original order. Deletion does not require freeing that particular node from memory. For custom tests, provide the entire list and a non-tail node from it; the driver passes that node to your function and checks the resulting list.

Source: Delete Node in a Linked List on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
head = [4,5,1,9], node = 5
Output
[4,1,9]

# Example 2

Input
head = [4,5,1,9], node = 1
Output
[4,5,9]

Constraints

The number of the nodes in the given list is in the range [2, 1000].
-1000 <= Node.val <= 1000
The value of each node in the list is unique.
The node to be deleted is in the list and is not a tail node.

Related LeetCode Problems

Practice more problems similar to Delete Node in a Linked List.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.