Remove duplicates from sorted list II

Problem Given the head of a sorted linked list, remove ALL nodes whose value appears more than once, keeping only values that were already distinct.

Input / Output

  • Input: head of sorted list.
  • Output: head of the filtered list.

Constraints

  • Up to 300 nodes classically; O(n) time, O(1) space, single pass preferred.

Example

  • 1→2→3→3→4→4→5 → 1→2→5 (contrast with variant I, which keeps one copy: 1→2→3→4→5).
asked …
LeaderboardSalaryAccount