0110. Balanced Binary Tree
Easy | Tree + DFS | 36 ms (99.59%), 17.9 MB (88.06%)
Source: LeetCode - Balanced Binary Tree GitHub: Solution / Performance
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as:
binary tree in which the left and right subtrees of every node differ in height by no more than 1.
Instead of calculating the height of each node's subtrees in each iteration, we utilize DFS to return height from the bottom while checking whether each node's subtrees are balanced or not.
Since the minimum height of a tree is 0 (the root is null), we could use '-1' to mark the node with unbalanced subtrees.
Last updated