Problem
A binary tree is height-balanced if, at every node, the heights of the left and right subtrees differ by at most 1. Given the root, return whether the tree is height-balanced.
Trees in the examples are written in level order (top to bottom, left to right), with null for a missing child, the same way the tests build them.
Example 1
- Input
- [3, 9, 20, null, null, 15, 7]
- Output
- True
Example 2
- Input
- [1, 2, 2, 3, 3, null, null, 4, 4]
- Output
- False
- Why
- left side is 3 deep, right is 1
Example 3
- Input
- []
- Output
- True
Constraints
0 <= number of nodes <= 5000-10^4 <= Node.val <= 10^4