From 50c188a88c4f5fa82ee7aa3af2b9a28d62393c25 Mon Sep 17 00:00:00 2001 From: marina <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Thu, 3 Aug 2023 15:56:35 -0700 Subject: [PATCH] notes on balanced --- trees/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/trees/README.md b/trees/README.md index 29fd54a..c0ee24f 100644 --- a/trees/README.md +++ b/trees/README.md @@ -39,6 +39,26 @@ def height(root):
+--- + +#### find if balanced + +
+ +```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) +``` + +
+ +--- + #### predecessor and successor