题解 | #顺时针旋转矩阵#
顺时针旋转矩阵
https://www.nowcoder.com/practice/2e95333fbdd4451395066957e24909cc
#include <vector>
class Solution {
public:
vector<vector<int> > rotateMatrix(vector<vector<int> > mat, int n) {
// write code here
for(int i = 0; i < n; i++){
for(int j = i; j < n; j++){
swap(mat[i][j], mat[j][i]); //时间复杂度为O(N^2),空间复杂度为O(1);
}
reverse(mat[i].begin(), mat[i].end());
}
return mat;
}
};