Skip to main content
LeetCode 203, Easy. Topics: Linked List, Recursion. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:

Problem

Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.

Examples

Example 1

Constraints

  • The number of nodes in the list is in the range [0, 10<sup>4</sup>]
  • 1 <= Node.val <= 50
  • 0 <= val <= 50

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026