Balanced Binary Tree
Given the root of a binary tree, determine whether it is height-balanced: for every node, the heights of its left and right subtrees differ by at most one.
Open official problem prompt ↗Check that no node in the tree has left and right subtrees whose heights differ by more than one.
Like inspecting a mobile hung from the ceiling: at every joint the two arms must hang at nearly the same length, or the whole thing tilts. One badly lopsided joint condemns the mobile.
- Input
- root = [3, 9, 20, null, null, 15, 7]
- Output
- true
- Why
- Every node's left and right subtree heights differ by at most 1, so the tree is balanced.
The number of nodes is in the range [0, 5000]-10^4 <= Node.val <= 10^4