Given the root of a binary tree, return true if the tree is height-balanced and false otherwise.
A tree is height-balanced when, at every node, the heights of its left and right subtrees differ by at most 1. The height of a subtree is the number of nodes on its longest downward path, and an empty subtree has height 0. An empty tree is balanced.
At the root both sides have height 2. Node 8 has an empty left side (height 0) and the single node 9 on its right (height 1), which is allowed.
The root is fine: both of its sides have height 3. But node 2 has a left side of height 2 and nothing on its right, a difference of 2, so the tree is not balanced.
Constraints
0 and 5000 nodes.-10⁴ <= Node.val <= 10⁴Balance has to hold at every node, not only at the root. Each node needs the heights of its two subtrees, and a node's height follows from its children's heights.
true