法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];
}
}
}
}