mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 14:56:27 -04:00
notes on balanced
This commit is contained in:
parent
817cbb57a2
commit
50c188a88c
1 changed files with 20 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue