You are given the head of a sorted linked list.
Your task is to delete all nodes that have duplicate values, leaving only distinct numbers from the original list.
You may assume that:
Return the modified linked list, which should still be sorted.
1 → 2 → 3 → 3 → 4 → 4 → 5 → null
1 → 2 → 5 → null
The values 3 and 4 each appear more than once, so all of their nodes are removed. Only 1, 2, and 5 remain.
1 → 1 → 1 → 2 → 3 → null
2 → 3 → null
The value 1 appears three times, so all nodes with value 1 are removed. Only 2 and 3 remain.
1 → 1 → 2 → 2 → null
None
Both values 1 and 2 have duplicates. All nodes are removed, resulting in an empty list.
1 → 2 → 3 → 3 → 4 → 4 → 5 → null
1 → 2 → 5 → null