Given the root of a binary tree, return true if the tree is height-balanced, otherwise return false.
A binary tree is considered height-balanced if for every node in the tree, the height difference between its left and right subtrees is not more than 1.
Example 1
Input: root = [3,9,20,null,null,15,7]
Output: true
Explanation: For every node, the height difference between the left and right subtrees is at most 1. Therefore, the tree is balanced.
Example 2
Input: root = [1,2,2,3,3,null,null,4,4]
Output: false
Explanation: The left subtree is deeper than the right subtree by more than 1 at some nodes. Hence, the tree is not height-balanced.
Example 3
Input: root = []
Output: true
Explanation: An empty tree is considered balanced because there are no nodes that violate the height condition.
Sign in to write, run, and submit your solution against the full test suite.