Leaning Tower Check
easyA structural engineer signs off on a tree-shaped scaffold only if no joint is dangerously lopsided: at every node, the heights of the left and right subtrees may differ by at most 1.
Given the root of a binary tree, return True if the tree is height-balanced by that rule, else False.
Tests pass a level-order array; implement the core in _balanced on real nodes.
Example 1
in values = [3, 9, 20, null, null, 15, 7]
out True
Example 2
in values = [1, 2, 2, 3, 3, null, null, 4, 4]
out False
At the root, the left side is two levels taller than the right.
Example 3
in values = []
out True
Constraints
- · 0 <= number of nodes <= 5000
- · -10^4 <= node value <= 10^4
solution.py● loading python…
test results
Hit ▶ Run to test your code against the visible cases.