We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 02b6e36 commit cdae90cCopy full SHA for cdae90c
1 file changed
algorithms/tree/is_balanced.py
@@ -13,7 +13,7 @@ def get_depth(root):
13
return 0
14
left = get_depth(root.left)
15
right = get_depth(root.right)
16
- if abs(left-right) > 1:
+ if abs(left-right) > 1 or left == -1 or right == -1:
17
return -1
18
return 1 + max(left, right)
19
0 commit comments