Skip to main content
LeetCode 1836, Medium. Topics: Hash Table, Linked List. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 24 parametrized pytest cases, and a playground notebook:

Problem

Given the head of a linked list, find all the values that appear more than once in the list and delete the nodes that have any of those values. Return the linked list after the deletions.

Examples

Example 1
Example 2
Example 3

Constraints

  • The number of nodes in the list is in the range [1, 10^5].
  • 1 <= Node.val <= 10^5

Solution

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

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026