Definition for a binary tree node.
Warning
Over a year old. May be outdated
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 than 14.05% of Python3 online submissions for Balanced Binary Tree.
Memory Usage
- 18.6 MB, less than 90.53% of Python3 online submissions for Balanced Binary Tree.
Complexity Analysis
Time
- because worst case, we might need to travel all nodes while counting their height with
Space
- because we require a stack to contain all nodes, worst case.
Other Answers Online
Backlinks2
220925Coding Tests