110. Balanced Binary Tree
My accepted Python solution to LeetCode problem 110, Balanced Binary Tree, running in 8ms.
- Difficulty: Easy
- Python
- Runtime 8ms
- Memory 17.9MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 8ms, memory 17.9MB, accepted 2025-12-23.
class Solution(object):
def isBalanced(self, root):
def height(node):
if not node:
return 0
left = height(node.left)
right = height(node.right)
if left == -1 or right == -1 or abs(left - right) > 1:
return -1
return 1 + max(left, right)
return height(root) != -1