Add two pointer solution to remove linked list dupes (#105)

This commit is contained in:
Donne Martin 2016-10-18 06:20:24 -04:00 committed by GitHub
parent 400dc8b55a
commit c961a279fc

View File

@ -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",