mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-13 21:08:06 +00:00
reverted files
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
"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",
|
||||
@@ -74,38 +75,20 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"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",
|
||||
"def is_substring(s1, s2):\n",
|
||||
" # TODO: Implement me\n",
|
||||
" pass\n",
|
||||
"\n",
|
||||
"def is_rotation(s1, s2):\n",
|
||||
" 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)"
|
||||
" # TODO: Implement me\n",
|
||||
" # Call is_substring only once\n",
|
||||
" pass"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -126,19 +109,11 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Success: test_rotation\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_rotation.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
@@ -188,7 +163,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.6"
|
||||
"version": "2.7.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user