Problem
Given the head of a sorted singly linked list, remove every node whose value appears more than once in the original list. Return the head of the sorted list containing only values that originally occurred exactly once. A repeated value contributes no surviving node.
The supplied ListNode has val and next fields. Preserve its pointer interface:
ListNode* deleteDuplicates(ListNode* head);
Brackets display a chain's values, not an array argument or array return.
Examples
Input: head = [-2,-2,0,3,3,8]
Output list: [0,8]
Input: head = [4,4]
Output list: []
Constraints
-
The list has between 0 and 300 nodes.
-
Node values are between -100 and 100, inclusive.
-
The input is sorted in ascending order, with equal values allowed.