Problem Statement:
Given a singly linked list. The task is to remove duplicates (nodes with duplicate values) from the given list (if it exists).
Note: Try not to use extra space. The nodes are arranged in a sorted way.
My Approach:
1.First I start with a pointer curr at the head of the linked list.
2.Then I compare current node data with curr.next.data.
3.If they are equal then I remove the next node by linking curr.next to curr.next.next.
4.If they are not equal then I move current node forward.
5.I repeat this until I reach the end of the list.
6.Finally then I return the modified head.

Top comments (0)