From 08fabdf58d2613e49af1c9e48a06c8397b7efa17 Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Mon, 15 Feb 2016 06:29:11 -0500 Subject: [PATCH] Tweak remove dupes solution to use a single node 'reference'. --- .../remove_duplicates_solution.ipynb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/linked_lists/remove_duplicates/remove_duplicates_solution.ipynb b/linked_lists/remove_duplicates/remove_duplicates_solution.ipynb index b297aa6..74e5a89 100644 --- a/linked_lists/remove_duplicates/remove_duplicates_solution.ipynb +++ b/linked_lists/remove_duplicates/remove_duplicates_solution.ipynb @@ -127,16 +127,16 @@ "class MyLinkedList(LinkedList):\n", "\n", " def remove_dupes(self):\n", - " seen_data = set()\n", - " curr = self.head\n", - " prev = None\n", - " while curr is not None:\n", - " if curr.data in seen_data:\n", - " prev.next = curr.next\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", + " node.next = node.next.next\n", " else:\n", - " seen_data.add(curr.data)\n", - " prev = curr\n", - " curr = curr.next\n", + " seen_data.add(node.next.data)\n", + " node = node.next\n", "\n", " def remove_dupes_in_place(self):\n", " curr = self.head\n",