Back to February Back to Year 2026
EASY 08 Feb 2026 View on LeetCode

110. Balanced Binary Tree

</> Solution

/**
 * Problem: LeetCode 110 - Balanced Binary Tree
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isBalanced(TreeNode root) {
        return checkHeight(root) != -1;
    }

    private int checkHeight(TreeNode node) {
        if (node == null) {
            return 0;
        }

        int leftHeight = checkHeight(node.left);
        if (leftHeight == -1) {
            return -1;
        }

        int rightHeight = checkHeight(node.right);
        if (rightHeight == -1) {
            return -1;
        }

        if (Math.abs(leftHeight - rightHeight) > 1) {
            return -1;
        }

        return 1 + Math.max(leftHeight, rightHeight);
    }
}

TIME COMPLEXITY

O(n)

SPACE COMPLEXITY

O(h)

TOPICS

Binary Tree Depth-First Search Recursion Tree