Stealth Interview
  • Features
  • Pricing
  • Blog
  • Login
  • Sign up

Leetcode #237: Delete Node in a Linked List

In this guide, we solve Leetcode #237 Delete Node in a Linked List in Python and focus on the core idea that makes the solution efficient.

You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Leetcode

Problem Statement

There is a singly-linked list head and we want to delete a node node in it. You are given the node to be deleted node.

Quick Facts

  • Difficulty: Medium
  • Premium: No
  • Tags: Linked List

Intuition

Linked list problems often require pointer manipulation rather than extra memory.

Two-pointer techniques expose cycles, midpoints, or reordering patterns.

Approach

Traverse with fast/slow pointers or reverse sublists when needed.

Maintain invariants carefully to avoid losing nodes.

Steps:

  • Traverse with pointers.
  • Reverse or split if required.
  • Reconnect nodes correctly.

Example

Input: head = [4,5,1,9], node = 5 Output: [4,1,9] Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.

Python Solution

# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteNode(self, node): """ :type node: ListNode :rtype: void Do not return anything, modify node in-place instead. """ node.val = node.next.val node.next = node.next.next

Complexity

The time complexity is O(n). The space complexity is O(1).

Edge Cases and Pitfalls

Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.

Summary

This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.


Ace your next coding interview

We're here to help you ace your next coding interview.

Subscribe
Stealth Interview
© 2026 Stealth Interview®Stealth Interview is a registered trademark. All rights reserved.
Product
  • Blog
  • Pricing
Company
  • Terms of Service
  • Privacy Policy