public boolean isBalancedRec(TreeNode root, TreeNode tmp){
        if(root == null) {
            return true;
        }
        TreeNode tmpL = new TreeNode(0);
        boolean isLeft = isBalancedRec(root.left, tmpL);
        TreeNode tmpR = new TreeNode(0);
        boolean isRight = isBalancedRec(root.right, tmpR);

        int hLeft = tmpL.val;
        int hRight = tmpR.val;

        tmp.val = Math.max(hLeft, hRight) + 1;

        return isLeft && isRight && Math.abs(hLeft - hRight) <= 1;
    }