LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 8ms, memory 17.9MB, accepted 2025-12-23.

python
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

Source