class Solution {
public void rotate(int[][] matrix) {
if(matrix == null || matrix.length == 0 || matrix[0].length == 0){
return;
}
int row = matrix.length;
int col = matrix[0].length;
//翻折90度 先对折 在竖折
for(int i=0; i< row; i++){
for(int j=0; j <= i; j++){
rotated(matrix, i, j, j, i);
}
}
for(int i=0; i< row; i++){
for(int j = 0; j < col/2; j++){
rotated(matrix, i, j, i, col-1-j);
}
}
}
public void rotated(int[][]matrix, int i, int j, int m, int n){
int temp = matrix[i][j];
matrix[i][j] = matrix[m][n];
matrix[m][n] = temp;
}
}
如果翻折90度 先对折再竖折 matrix[i][j] = matrix[j][i]
如果翻折180度 先横折再竖折 matrix[i][j] = matrix[i][col-1-j]
如果翻折270度 先对折再横折 matrix[i][j] = matrix[col-1-i][j]