mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Add two pointer solution to remove linked list dupes (#105)
This commit is contained in:
parent
400dc8b55a
commit
c961a279fc
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue
Block a user