Balanced Binary Tree
Return whether every node has left and right subtree heights differing by at most one.
Example 1
root = [1,2,3,4]trueExplanation
Node 2 has one child and the root's heights differ by one; all nodes are balanced.
Example 2
root = [1,2,null,3]falseExplanation
The root has left height two and right height zero, violating balance.
Example 3
root = []trueExplanation
An empty tree has no violating node.
Constraints
- 0 <= number of nodes <= 5000
- Trees are breadth-first arrays with null holes
Function contract
isBalancedArguments: treeSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[1,2,3,4]