notes on balanced

This commit is contained in:
marina 2023-08-03 15:56:35 -07:00 committed by GitHub
parent 817cbb57a2
commit 50c188a88c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,6 +39,26 @@ def height(root):
<br> <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 #### predecessor and successor
<br> <br>