public static boolean isBalanced(TreeNode root) {
        // write your code here
        if (root==null)
            return true;
        Map<TreeNode, Integer>map=new HashMap<>();
        return isBalanced(root.left)&&isBalanced(root.right)&&(Math.abs(height(root.left, map)-height(root.right, map))<=1);
    }