LeetCode 110
Balanced Binary Tree
Concepts:
Tree
Description: Given a binary tree, determine if it is height-balanced.
Brute-force Approach
Simple recursion, calculate height of the left and right subtrees and check if the node is balanced. Recursively check if the left and right subtrees are balanced.
Time: O(n^2)
Space: O(1), Recursive stack space: O(n)
Optimal Approach
Using post order recursion, calculate height and check if the tree is balanced simultaneously.
Time: O(n)
Space: O(1), Recursive stack space: O(n)