REMDUP Editorial

Problem Explanation

We are given a sorted linked list and we have to remove all the duplicates from the linked list and return the sorted linked list with unique values.

Approach

Since the linked list is sorted, the duplicate values will be right next to one another. We can iterate over the linked list and if the next value is equal to the current value we delete the next node. To delete the node we set the current’s next pointer to the next of the next node. and then delete the next node.