class Solution {
public void rotate(int[][] matrix) {
int length=matrix.length;
int temp=0;
for(int row=0;row<length/2;row++){
for(int col=row;col<length-row-1;col++){
temp=matrix[row][col];//将左上角的数存起来
matrix[row][col]=matrix[length-col-1][row];//将左下角的数赋值给左上角
matrix[length-col-1][row]=matrix[length-row-1][length-col-1];//将右下角的数赋值给左下角
matrix[length-row-1][length-col-1]=matrix[col][length-row-1];//将右上角的数赋值给右下角
matrix[col][length-row-1]=temp;//将左上角的数赋值给右上角
//System.out.println(Arrays.deepToString(matrix));
}
}
}
}
大致思路如下: