mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update bst_is_balanced.py
This commit is contained in:
parent
f7dc8af9c4
commit
39922339a3
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
def height(root):
|
def height(root):
|
||||||
|
|
||||||
if not root:
|
if root is None:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
return 1 + max(height(root.left), height(root.right))
|
return 1 + max(height(root.left), height(root.right))
|
||||||
@ -13,7 +13,7 @@ def height(root):
|
|||||||
|
|
||||||
def is_balanced(root):
|
def is_balanced(root):
|
||||||
|
|
||||||
if not root:
|
if root is None:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return abs(height(root.left) - height(root.right)) < 2 and \
|
return abs(height(root.left) - height(root.right)) < 2 and \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user