AI Features

Solution Review: Remove Duplicates

This lesson contains the solution review for the challenge of removing duplicates from a doubly linked list.

We'll cover the following...

In this lesson, we consider how to remove duplicates from a doubly linked list.

Implementation

Check out the code below:

def remove_duplicates(self):
cur = self.head
seen = dict()
while cur:
if cur.data not in seen:
seen[cur.data] = 1
cur = cur.next
else:
nxt = cur.next
self.delete_node(cur)
cur = nxt
...