N*N型矩阵旋转90°相当于矩阵上下对折再沿对角线对折,即:
public class l2047 {
public void rotate(int[][] matrix) {
int size = matrix.length;
for (int row = 0; row < size / 2; row++) {
for (int col = 0; col < size; col++) {
int temp = matrix[row][col];
matrix[row][col] = matrix[size - row - 1][col];
matrix[size - row - 1][col] = temp;
}
}
for(int row = 0 ; row < size ; row++){
for(int col = 0 ; col < row+1 ; col ++){
int temp = matrix[row][col];
matrix[row][col] = matrix[col][row];
matrix[col][row] = temp;
}
}
}
}