题解 | #顺时针旋转矩阵#
顺时针旋转矩阵
http://www.nowcoder.com/practice/2e95333fbdd4451395066957e24909cc
利用数学中的旋转性质,可以求出旋转后的坐标,对应到数组中即可。代码如下:
public class Solution {
public int[][] rotateMatrix(int[][] mat, int n) {
// write code here
int[][] res = new int[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
res[i][j] = mat[n-j-1][i];
}
}
return res;
}
}
SHEIN希音公司福利 370人发布