public boolean isBalanced(TreeNode root) {
        if (root == null)
            return true;
        int leftDepth = maxDepth(root.left);
        int rightDepth = maxDepth(root.right);
        return Math.abs(leftDepth - rightDepth) <= 1 && isBalanced(root.left)
                && isBalanced(root.right);
    }