From c961a279fc07b42f4253f09298fb7a4a160a79e0 Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Tue, 18 Oct 2016 06:20:24 -0400 Subject: [PATCH] Add two pointer solution to remove linked list dupes (#105) --- .../remove_duplicates_solution.ipynb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/linked_lists/remove_duplicates/remove_duplicates_solution.ipynb b/linked_lists/remove_duplicates/remove_duplicates_solution.ipynb index 1e43301..77f598b 100644 --- a/linked_lists/remove_duplicates/remove_duplicates_solution.ipynb +++ b/linked_lists/remove_duplicates/remove_duplicates_solution.ipynb @@ -127,6 +127,20 @@ " if self.head is None:\n", " return\n", " node = self.head\n", + " seen_data = set()\n", + " while node is not None:\n", + " if node.data not in seen_data:\n", + " seen_data.add(node.data)\n", + " prev = node\n", + " node = node.next\n", + " else:\n", + " prev.next = node.next\n", + " node = node.next\n", + "\n", + " def remove_dupes_single_pointer(self):\n", + " if self.head is None:\n", + " return\n", + " node = self.head\n", " seen_data = set({node.data})\n", " while node.next is not None:\n", " if node.next.data in seen_data:\n",