Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def remove_duplicates(self):
- if self.head is None:
- return
- target = curr = self.head
- while curr is not None:
- if curr.next is not None:
- if curr.next.value == target.value:
- curr.next = curr.next.next
- self.length -= 1
- else:
- target = curr = target.next
- curr = curr.next
- # Output:
- # Before: [2, 3, 1, 2, 4, 5, 4, 4, 2, 3, 2, 5, 4]
- # After: [2, 3, 1, 4, 5, 4, 5]
Advertisement
Add Comment
Please, Sign In to add comment