Skip to main content
Back to problems
Leetcode
Medium
Linked Lists
Delete Node In A Linked List

Delete a node from a singly linked list when only that node is given.

Acceptance 100%
Problem Statement

Problem

You are given a reference to a node in a singly linked list. The node to delete is not the tail of the list.

Remove that node from the list so that the linked list no longer contains it, and the relative order of the remaining nodes stays the same.

You do not have access to the head of the list.

Important constraint

Because the head is unavailable, you cannot simply search for the previous node. Instead, you must modify the list in place using only the given node.

Goal

Update the linked list so that the given node is logically deleted from the chain.

Input Format

  • A reference to a node in a singly linked list.
  • The node is guaranteed to be non-tail.
  • The linked list nodes contain integer values.

Output Format

Return nothing. Modify the linked list in place by deleting the given node.

Constraints

  • The given node is guaranteed to have a next node.
  • The list is singly linked.
  • You may not access the head node.
  • The node to delete is guaranteed not to be the tail.
Examples
Sample cases returned by the problem API.

Example 1

Input

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

Output

head = [4,1,9]

Explanation

Copy the value from the next node into the given node, then bypass the next node. The list becomes 4 -> 1 -> 9.

Example 2

Input

head = [1,2,3,4], node = 3

Output

head = [1,2,4]

Explanation

The node with value 3 is replaced in place by its next node's value, and the next node is removed from the chain.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.