题解 | #顺时针旋转矩阵#
顺时针旋转矩阵
https://www.nowcoder.com/practice/2e95333fbdd4451395066957e24909cc
class Solution {
public:
vector<vector<int> > rotateMatrix(vector<vector<int> > mat, int n) {
// write code here
vector<vector<int>> result(n,vector<int>(n));
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
result[i][j]=mat[n-j-1][i]; //哈哈,就是每列变为每行呗
}
}
return result;
}
};
public:
vector<vector<int> > rotateMatrix(vector<vector<int> > mat, int n) {
// write code here
vector<vector<int>> result(n,vector<int>(n));
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
result[i][j]=mat[n-j-1][i]; //哈哈,就是每列变为每行呗
}
}
return result;
}
};