Balanced Binary Tree

Check if tree is height-balanced

Read Here
Step0/55
Status-
Current-
Back To Trees List

Code (Python)

......
2 def __init__(self, val=0, left=None, right=None):
3 self.val = val
4 self.left = left
5 self.right = right
6
7class Solution:
def isBalanced(self, root) -> bool:
9 def check(node):
10 if not node: # null leaf has height 0
11 return 0
12
13 left = check(node.left)
14 if left == -1: # early exit - left unbalanced
......
Current Line (7): Function Entry
9157203

Traversal Progress

Current Node

-

Phase

Enter

Status

UNBALANCED

Step 1: ENTER

Recursion Stack

Stack is empty. Click Next to begin!

Explanation

Click Run to start