fixed problems, new pull

This commit is contained in:
wdonahoe
2015-07-11 10:43:28 -04:00
parent f703014dec
commit b4476d3f77
10 changed files with 193 additions and 65 deletions

View File

@@ -34,7 +34,6 @@
"source": [
"## Constraints\n",
"\n",
"* Can you assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
@@ -75,20 +74,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def is_substring(s1, s2):\n",
" # TODO: Implement me\n",
" pass\n",
"def is_substring(substr, s):\n",
" if len(s) < len(substr):\n",
" return False\n",
" elif len(substr) == len(s) and len(s) == 0:\n",
" return True\n",
" pos = 0\n",
" while pos < len(s):\n",
" so_far = 0\n",
" while so_far < len(substr):\n",
" if substr[so_far] != s[pos]:\n",
" pos = pos + 1\n",
" break\n",
" else:\n",
" pos = pos + 1\n",
" so_far = so_far + 1\n",
" if so_far == len(substr):\n",
" return True\n",
" return False\n",
"\n",
"def is_rotation(s1, s2):\n",
" # TODO: Implement me\n",
" # Call is_substring only once\n",
" pass"
" if s1 is None or s2 is None:\n",
" return False\n",
" elif len(s1) != len(s2):\n",
" return False\n",
" else:\n",
" return is_substring(s2,s1+s1)"
]
},
{
@@ -109,11 +126,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_rotation\n"
]
}
],
"source": [
"# %load test_rotation.py\n",
"from nose.tools import assert_equal\n",
@@ -163,7 +188,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
"version": "2.7.6"
}
},
"nbformat": 4,