题解 | #顺时针旋转矩阵#
顺时针旋转矩阵
https://www.nowcoder.com/practice/2e95333fbdd4451395066957e24909cc
#include <vector> class Solution { public: vector<vector<int> > rotateMatrix(vector<vector<int> > mat, int n) { // write code here if(mat.size() == 0) return {}; vector<vector<int> > res(n,vector<int>(n,0)); for(int i = 0;i<n;++i) { for(int j = n-1;j>=0;--j) { res[i][n-1-j] = mat[j][i]; } } return res; } };
旋转后,原矩阵每一列的逆序变成了新矩阵的每一行