We’re preparing your current view and syncing the latest data.
Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.
A singly linked list head with nodes sorted in non-decreasing order.
The head of the modified linked list, where all duplicates have been removed.
The number of nodes in the list is in the range [0, 300]. -100 <= Node.val <= 100 The list is sorted in non-decreasing order.
Example 1
Input
head = [1,1,2]
Output
[1,2]
Explanation
The first two elements are duplicates, so we remove one instance.
Example 2
Input
head = [1,1,2,3,3]
Output
[1,2,3]
Explanation
Duplicates 1 and 3 are removed leaving distinct elements.