法1:辅助矩阵
java
class Solution {
public void rotate(int[][] matrix) {
int n = matrix.length;
int[][] newMatrix = new int[n][];
for (int i = 0;i < n; ++i) {
newMatrix[i] = matrix[i].clone();
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
matrix[j][n - 1 - i] = newMatrix[i][j];
}
}
}
}
法2:原地旋转
直接看上方参考链接。。