Refactored test cases, tests are now called for all three algorithms. Tweaked algorithm description for in-place approach.

This commit is contained in:
Donne Martin 2015-06-19 23:07:35 -04:00
parent f9094c4908
commit 0dd0b98f1b

View File

@ -79,11 +79,23 @@
"outputs": [],
"source": [
"def unique_chars(string):\n",
" return len(set(string)) == len(string)\n",
" return len(set(string)) == len(string)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def test():\n",
" print(unique_chars(''))\n",
" print(unique_chars('foo'))\n",
" print(unique_chars('bar'))\n",
"\n",
"print(unique_chars(''))\n",
"print(unique_chars('foo'))\n",
"print(unique_chars('bar'))"
"test()"
]
},
{
@ -132,7 +144,9 @@
" return False\n",
" else:\n",
" chars_set.add(char)\n",
" return True"
" return True\n",
"\n",
"test()"
]
},
{
@ -141,7 +155,7 @@
"source": [
"## Algorithm 3: In-Place\n",
"\n",
"Since we cannot use additional data structures, this will eliminate the fast lookup O(1) time provided by our hash map.\n",
"Assume we cannot use additional data structures, which will eliminate the fast lookup O(1) time provided by our hash map. \n",
"* Scan each character\n",
"* For each character:\n",
" * Scan all [other] characters in the array\n",
@ -173,7 +187,9 @@
" for char in string:\n",
" if string.count(char) > 1:\n",
" return False\n",
" return True"
" return True\n",
"\n",
"test()"
]
}
],