Skip to main content
LeetCode 82, Medium. Topics: Linked List, Two Pointers. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 23 parametrized pytest cases, and a playground notebook:

Problem

Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.

Examples

Example 1
Example 2

Constraints

  • The number of nodes in the list is in the range [0, 300].
  • -100 <= Node.val <= 100
  • The list is guaranteed to be sorted in ascending order.

Solution

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

Complexity

Tags

Last modified on September 7, 2026