Skip to main content
Back to problems
#237
Medium Algorithms

Delete node in a linked list

Linked List
83.6% acceptance
Jan 13, 2026
6246
1780
There is a singly-linked list head and we want to delete a node in it. You are given the node to be deleted. You will not be given access to the first node of head. The node to be deleted is not the last node.

Solution

C++
Time O(1)
Space O(1)
LeetCode
solution.cpp
class Solution {
public:
  void deleteNode(ListNode* node) {
    node->val = node->next->val;
    node->next = node->next->next;
  }
};