https://blog.nowcoder.net/detail/0?qurl=/practice/2e95333fbdd4451395066957e24909cc
这题其实就是找规律,所谓的矩阵顺时针旋转,其实就是将原来的矩阵每列从下到上写到新矩阵的每行从左到右
public class Solution {
public int[][] rotateMatrix(int[][] mat, int n) {
if(mat==null||mat[0].length==0) return new int[][]{};
int rows = n;
int cols = n;
int[][] res = new int[cols][rows];
for(int col = 0;col<cols;col++){
int w = 0;
for(int row = rows-1;row>=0;row--){
//每列从下到上填入新数组的每行从左到右
res[col][w++] = mat[row][col];
}
}
return res;
}
} 
京公网安备 11010502036488号