Remove Duplicates from Sorted Linked List
Innovaccer deals with vast amounts of patient data, often received from various sources. This data needs to be cleaned and standardized for accurate analysis. One common issue is redundant entries, especially when data is aggregated from pre-sorted feeds. Your task is to implement a function that removes duplicate nodes from a sorted singly linked list, ensuring each value appears only once. This is crucial for maintaining data integrity and optimizing storage/processing efficiency in our data pipelines.
Implement a function deleteDuplicates that takes the head of a sorted singly linked list as input. The function should remove all duplicate nodes such that each element appears only once. The resulting list should also be sorted.
head: A ListNode representing the head of a sorted singly linked list. Each ListNode has an integer val and a next pointer to the next node.ListNode representing the head of the modified sorted singly linked list with duplicates removed.val of nodes will be within standard integer limits.Examples
Example 1
Input:
head = [1,1,2]
Output:
[1,2]
Note:
The original list is 1 -> 1 -> 2. The duplicate '1' is removed, resulting in 1 -> 2.
Example 2
Input:
head = [1,1,2,3,3]
Output:
[1,2,3]
Note:
The original list is 1 -> 1 -> 2 -> 3 -> 3. Duplicate '1' and '3' are removed, resulting in 1 -> 2 -> 3.
Example 3
Input:
head = [1,2,3]
Output:
[1,2,3]
Note:
The list contains no duplicates, so it remains unchanged.
Example 4
Input:
head = []
Output:
[]
Note:
An empty list remains empty.
Constraints
0 and 300.-100 <= Node.val <= 100.Loading editor...