Definition for a binary tree node.
Solved at: 220925
Question
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as:
a binary tree in which the left and right subtrees of every node differ in height by no more than 1.
Solution
Results
Runtime
- 123 ms, faster than14.05%ofPython3online submissions forBalanced Binary Tree.
Memory Usage
- 18.6 MB, less than90.53%ofPython3online submissions forBalanced Binary Tree.
Complexity Analysis
Time
- $O(n \log n)$ because worst case, we might need to travel all nodes while counting their height with $O(n)$
Space
- $O(n)$ because we require a stack to contain all nodes, worst case.
Other Answers Online
Backlinks (2)