From 0dd0b98f1b62c13bde9345582e9f7e31f46228bc Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Fri, 19 Jun 2015 23:07:35 -0400 Subject: [PATCH] Refactored test cases, tests are now called for all three algorithms. Tweaked algorithm description for in-place approach. --- arrays-strings/unique_chars.ipynb | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/arrays-strings/unique_chars.ipynb b/arrays-strings/unique_chars.ipynb index f8e7618..ad89b7c 100644 --- a/arrays-strings/unique_chars.ipynb +++ b/arrays-strings/unique_chars.ipynb @@ -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()" ] } ],