mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
notes on balanced
This commit is contained in:
parent
817cbb57a2
commit
50c188a88c
@ -39,6 +39,26 @@ def height(root):
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
#### find if balanced
|
||||
|
||||
<br>
|
||||
|
||||
```python
|
||||
def is_balanced(root):
|
||||
|
||||
if not root:
|
||||
return True
|
||||
|
||||
return abs(height(root.left) - height(root.right)) < 2 and \
|
||||
is_balanced(root.left) and is_balanced(root.right)
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
#### predecessor and successor
|
||||
|
||||
<br>
|
||||
|
Loading…
x
Reference in New Issue
Block a user