mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Tweak remove dupes solution to use a single node 'reference'.
This commit is contained in:
parent
21add6f4f5
commit
08fabdf58d
|
@ -127,16 +127,16 @@
|
||||||
"class MyLinkedList(LinkedList):\n",
|
"class MyLinkedList(LinkedList):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def remove_dupes(self):\n",
|
" def remove_dupes(self):\n",
|
||||||
" seen_data = set()\n",
|
" if self.head is None:\n",
|
||||||
" curr = self.head\n",
|
" return\n",
|
||||||
" prev = None\n",
|
" node = self.head\n",
|
||||||
" while curr is not None:\n",
|
" seen_data = set({node.data})\n",
|
||||||
" if curr.data in seen_data:\n",
|
" while node.next is not None:\n",
|
||||||
" prev.next = curr.next\n",
|
" if node.next.data in seen_data:\n",
|
||||||
|
" node.next = node.next.next\n",
|
||||||
" else:\n",
|
" else:\n",
|
||||||
" seen_data.add(curr.data)\n",
|
" seen_data.add(node.next.data)\n",
|
||||||
" prev = curr\n",
|
" node = node.next\n",
|
||||||
" curr = curr.next\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
" def remove_dupes_in_place(self):\n",
|
" def remove_dupes_in_place(self):\n",
|
||||||
" curr = self.head\n",
|
" curr = self.head\n",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user