题解 | #顺时针旋转矩阵#
顺时针旋转矩阵
https://www.nowcoder.com/practice/2e95333fbdd4451395066957e24909cc
先转置,再水平翻转即可
class Solution { public: vector<vector<int> > rotateMatrix(vector<vector<int> >& mat, int n) { for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { swap(mat[i][j], mat[j][i]); } reverse(mat[i].begin(), mat[i].end()); } return mat; } };