public boolean isBalanced(TreeNode root) {//passed without testing on ide
        if (root == null) {
            return true;
        }
        if (Math.abs(maxDepth(root.left) - maxDepth(root.right)) < 2 &&
                isBalanced(root.left) && isBalanced(root.right)) {
            return true;
        }
        else return false;
    }