static void rotate(int[][] matrix) {
        int n = matrix.length;
        int tmp;
        for (int offset = 0; offset < n/2; offset++) {
            for (int i = offset; i<offset+n-2*offset-1; i++) {
                tmp = matrix[offset][i];
                matrix[offset][i] = matrix[n-1-i][offset];
                matrix[n-1-i][offset] = matrix[n-1-offset][n-1-i];
                matrix[n-1-offset][n-1-i] = matrix[i][n-1-offset];
                matrix[i][n-1-offset] = tmp;
            }
        }
    }