public int[][] rotateMatrix(int[][] mat, int n) {
// write code here
if (mat == null){
return null;
}
if (n <= 1){
return mat;
}
int[][] res = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
res[j][n-i-1] = mat[i][j];
}
}
return res;
}
京公网安备 11010502036488号