mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Fixed Python2 vs Python3 division compatibility.
This commit is contained in:
parent
40ef096ede
commit
53f7c0e4d8
|
@ -36,7 +36,6 @@
|
||||||
"source": [
|
"source": [
|
||||||
"## Constraints\n",
|
"## Constraints\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|
||||||
"* Can I assume the string is ASCII?\n",
|
"* Can I assume the string is ASCII?\n",
|
||||||
" * Yes\n",
|
" * Yes\n",
|
||||||
" * Note: Unicode strings could require special handling depending on your language\n",
|
" * Note: Unicode strings could require special handling depending on your language\n",
|
||||||
|
@ -92,11 +91,14 @@
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
"from __future__ import division\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
"def list_of_chars(chars):\n",
|
"def list_of_chars(chars):\n",
|
||||||
" if chars is None:\n",
|
" if chars is None:\n",
|
||||||
" return None\n",
|
" return None\n",
|
||||||
" size = len(chars)\n",
|
" size = len(chars)\n",
|
||||||
" for i in range(size/2):\n",
|
" for i in range(size//2):\n",
|
||||||
" chars[i], chars[size-1-i] = \\\n",
|
" chars[i], chars[size-1-i] = \\\n",
|
||||||
" chars[size-1-i], chars[i]\n",
|
" chars[size-1-i], chars[i]\n",
|
||||||
" return chars"
|
" return chars"
|
||||||
|
|
|
@ -113,7 +113,7 @@
|
||||||
"def merge_sort(data):\n",
|
"def merge_sort(data):\n",
|
||||||
" if len(data) < 2:\n",
|
" if len(data) < 2:\n",
|
||||||
" return data\n",
|
" return data\n",
|
||||||
" mid = int(len(data) / 2)\n",
|
" mid = len(data) // 2\n",
|
||||||
" left = data[0:mid]\n",
|
" left = data[0:mid]\n",
|
||||||
" right = data[mid:len(data)]\n",
|
" right = data[mid:len(data)]\n",
|
||||||
" left = merge_sort(left)\n",
|
" left = merge_sort(left)\n",
|
||||||
|
|
|
@ -94,7 +94,7 @@
|
||||||
" return data\n",
|
" return data\n",
|
||||||
" left = []\n",
|
" left = []\n",
|
||||||
" right = []\n",
|
" right = []\n",
|
||||||
" pivot_index = int(len(data) / 2)\n",
|
" pivot_index = len(data) // 2\n",
|
||||||
" pivot_value = data[pivot_index]\n",
|
" pivot_value = data[pivot_index]\n",
|
||||||
" \n",
|
" \n",
|
||||||
" # Build the left and right partitions\n",
|
" # Build the left and right partitions\n",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user