mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Tweaked utopian tree algorithm discussion, cleared challenge code section.
This commit is contained in:
parent
3061020cc1
commit
d4a2300ea0
|
@ -68,7 +68,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
|
@ -78,15 +78,8 @@
|
||||||
"# cycles = 1, print 2: i = 1: 1 * 2\n",
|
"# cycles = 1, print 2: i = 1: 1 * 2\n",
|
||||||
"# cycles = 4, print 7: i = 1: 1 * 2, i = 2: 2 + 1, i = 3: 3 * 2, i = 4: 6 + 1\n",
|
"# cycles = 4, print 7: i = 1: 1 * 2, i = 2: 2 + 1, i = 3: 3 * 2, i = 4: 6 + 1\n",
|
||||||
"def calc_utopian_tree_height(cycles):\n",
|
"def calc_utopian_tree_height(cycles):\n",
|
||||||
" height = 1\n",
|
" # TODO: Implement me\n",
|
||||||
" if cycles == 0:\n",
|
" pass"
|
||||||
" return height\n",
|
|
||||||
" for i in xrange(1, cycles+1):\n",
|
|
||||||
" if i % 2 == 1:\n",
|
|
||||||
" height *= 2\n",
|
|
||||||
" else:\n",
|
|
||||||
" height += 1\n",
|
|
||||||
" return height"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
"* Return height\n",
|
"* Return height\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Complexity:\n",
|
"Complexity:\n",
|
||||||
"* Time: O(n), where n is the number of cycles, for each cycle we perform a calculation\n",
|
"* Time: O(n)\n",
|
||||||
"* Space: O(1)"
|
"* Space: O(1)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user