DEV Community

Saranya R
Saranya R

Posted on

Remove Duplicates in Sorted Linked List

Approach Explanation (* ̄▽ ̄)/

  1. Because the list is sorted, duplicates will always be adjacent.
  2. I traversed the list using a pointer curr.
  3. If curr.data == curr.next.data, I skipped the duplicate node by reassigning curr.next.
  4. Otherwise, I moved forward.
  5. At the end, only one copy of each value remained.

Method Used: (〜 ̄▽ ̄)〜

  • Single traversal
  • Pointer adjustment
  • No extra space

Top comments (0)