Guest User

Untitled

a guest
Jan 18th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. def remove_duplicates(self):
  2.     if self.head is None:
  3.         return
  4.     target = curr = self.head
  5.     while curr is not None:
  6.         if curr.next is not None:
  7.             if curr.next.value == target.value:
  8.                 curr.next = curr.next.next
  9.                 self.length -= 1
  10.         else:
  11.             target = curr = target.next
  12.         curr = curr.next
  13.  
  14. # Output:
  15. # Before: [2, 3, 1, 2, 4, 5, 4, 4, 2, 3, 2, 5, 4]
  16. # After: [2, 3, 1, 4, 5, 4, 5]
Advertisement
Add Comment
Please, Sign In to add comment