Skip to content

Commit cdae90c

Browse files
jesilikeon
authored andcommitted
Update is_balanced.py (keon#398)
fixed a little bug
1 parent 02b6e36 commit cdae90c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

algorithms/tree/is_balanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def get_depth(root):
1313
return 0
1414
left = get_depth(root.left)
1515
right = get_depth(root.right)
16-
if abs(left-right) > 1:
16+
if abs(left-right) > 1 or left == -1 or right == -1:
1717
return -1
1818
return 1 + max(left, right)
1919

0 commit comments

Comments
 (0)