数据范围:0 < n < 3000<n<300,矩阵中的值满足 0 \le val \le 10000≤val≤1000
示例1
输入:
[[1,2,3],[4,5,6],[7,8,9]],3
返回值:
[[7,4,1],[8,5,2],[9,6,3]]
代码
class Solution {
public:
vector<vector<int> > rotateMatrix(vector<vector<int> > mat, int n) {
// write code here
vector<vector<int> >res;
int k=0;
do
{
vector<int>temp;
for(int i=0;i<mat.size();i++)
{
vector<int>sub=mat[i];
for(int j=0;j<1;j++)
{
temp.push_back(sub[k]);
}
}
for(int m=0;m<n;m++)
{
cout<<temp[m]<<" ";
}
cout<<endl;
reverse(temp.begin(),temp.end());
res.push_back(temp);
k++;
if(k==n)
break;
}
while(1);
return res;
}
};