public void rotate(int[][] matrix) {
// put upside down
int rows = matrix.length;
int cols = matrix[0].length;
for (int r = 0; r < rows / 2; r++)
{
for (int c = 0; c < cols; c++)
{
int tmp = matrix[r][c];
matrix[r][c] = matrix[rows-r-1][c];
matrix[rows-r-1][c] = tmp;
}
}
// reverse diagnal
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < r; c++)
{
int tmp = matrix[r][c];
matrix[r][c] = matrix[c][r];
matrix[c][r] = tmp;
}
}
}
03-29