mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Fix check balance challenge spacing
This commit is contained in:
parent
6119c3043f
commit
1e05d35fca
|
@ -104,16 +104,16 @@
|
|||
"source": [
|
||||
"class BstBalance(Bst):\n",
|
||||
"\n",
|
||||
" def _check_height(self, node):\n",
|
||||
" def _check_balance(self, node):\n",
|
||||
" if node is None:\n",
|
||||
" return 0\n",
|
||||
" left_height = self._check_height(node.left)\n",
|
||||
" left_height = self._check_balance(node.left)\n",
|
||||
" if left_height == -1:\n",
|
||||
" return -1\n",
|
||||
" right_height = self._check_height(node.right)\n",
|
||||
" right_height = self._check_balance(node.right)\n",
|
||||
" if right_height == -1:\n",
|
||||
" return -1\n",
|
||||
" diff = abs(left_height-right_height)\n",
|
||||
" diff = abs(left_height - right_height)\n",
|
||||
" if diff > 1:\n",
|
||||
" return -1\n",
|
||||
" return 1 + max(left_height, right_height)\n",
|
||||
|
@ -121,7 +121,7 @@
|
|||
" def check_balance(self):\n",
|
||||
" if self.root is None:\n",
|
||||
" raise TypeError('root cannot be None')\n",
|
||||
" height = self._check_height(self.root)\n",
|
||||
" height = self._check_balance(self.root)\n",
|
||||
" return height != -1"
|
||||
]
|
||||
},
|
||||
|
@ -235,7 +235,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.5.0"
|
||||
"version": "3.4.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
Loading…
Reference in New Issue
Block a user