mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Polish remove duplicates challenge and solution
Update constraints and algorithm discussion.
This commit is contained in:
parent
94aaedb49f
commit
8cc41e23af
|
@ -38,9 +38,11 @@
|
|||
" * Singly\n",
|
||||
"* Can you insert None values in the list?\n",
|
||||
" * No\n",
|
||||
"* Can you use additional data structures?\n",
|
||||
" * Implement both solutions\n",
|
||||
"* Can we assume we already have a linked list class that can be used for this problem?\n",
|
||||
" * Yes\n",
|
||||
"* Can we use additional data structures?\n",
|
||||
" * Implement both solutions\n",
|
||||
"* Can we assume this fits in memory?\n",
|
||||
" * Yes"
|
||||
]
|
||||
},
|
||||
|
@ -193,7 +195,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.4.3"
|
||||
"version": "3.5.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
|
@ -38,9 +38,11 @@
|
|||
" * Singly\n",
|
||||
"* Can you insert None values in the list?\n",
|
||||
" * No\n",
|
||||
"* Can you use additional data structures?\n",
|
||||
" * Implement both solutions\n",
|
||||
"* Can we assume we already have a linked list class that can be used for this problem?\n",
|
||||
" * Yes\n",
|
||||
"* Can we use additional data structures?\n",
|
||||
" * Implement both solutions\n",
|
||||
"* Can we assume this fits in memory?\n",
|
||||
" * Yes"
|
||||
]
|
||||
},
|
||||
|
@ -62,6 +64,8 @@
|
|||
"source": [
|
||||
"## Algorithm: Hash Map Lookup\n",
|
||||
"\n",
|
||||
"Loop through each node\n",
|
||||
"\n",
|
||||
"* For each node\n",
|
||||
" * If the node's value is in the hash map\n",
|
||||
" * Delete the node\n",
|
||||
|
@ -70,10 +74,7 @@
|
|||
"\n",
|
||||
"Complexity:\n",
|
||||
"* Time: O(n)\n",
|
||||
"* Space: O(n)\n",
|
||||
"\n",
|
||||
"Note:\n",
|
||||
"* Deletion requires two pointers, one to the previous node and one to the current node"
|
||||
"* Space: O(n)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -84,17 +85,13 @@
|
|||
"\n",
|
||||
"* For each node\n",
|
||||
" * Compare node with every other node\n",
|
||||
" * If the node's value is in the hash map\n",
|
||||
" * Delete the node\n",
|
||||
" * Else\n",
|
||||
" * Add node's value to the hash map\n",
|
||||
" * Delete nodes that match current node\n",
|
||||
"\n",
|
||||
"Complexity:\n",
|
||||
"* Time: O(n^2)\n",
|
||||
"* Space: O(1)\n",
|
||||
"\n",
|
||||
"Note:\n",
|
||||
"* Deletion requires two pointers, one to the previous node and one to the current node\n",
|
||||
"* We'll need to use a 'runner' to check every other node and compare it to the current node"
|
||||
]
|
||||
},
|
||||
|
@ -258,7 +255,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.4.3"
|
||||
"version": "3.5.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
Loading…
Reference in New Issue
Block a user