Example 4 : Remove Duplicates from Sorted List

TopicDifficultyCompanies
Array and Linked-List
MEDIUM
Microsoft
VMWare

Given a sorted linked list, write a program to delete all duplicates such that each element appear only once.

Example 1

Input: 1->1->1->1->2->2->2
Output: 1->2
Explanation: After removing duplicates, 1->1->1->1->2->2->2 becomes 1->2.

Example 2

Input: 11->12->12->33->33
Output: 11->12->33
Explanation: After removing duplicates, 11->12->12->33->33 becomes 11->12->33.

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.