matrix里的数值旋转90度

class Solution {
public:
  void rotate(vector<vector<int>>& matrix) {
  vector<vector<int>> res;
  vector<int> ans;
  if(matrix.empty())
  {
    return ;
  }
  int top = 0;
  int bottom = matrix.size()-1;
  int left = 0;
  int right = matrix[0].size()-1;
  while(left<=right)
  {
  for(int i=bottom;i>=top;i--)
  {
    ans.push_back(matrix[i][left]);
  }
  left ++;
  res.push_back(ans);
  int n = ans.size();
  while(n!=0)
  {
      ans.pop_back();
      n --;
  }
}
for(int i=0;i<res.size();i++)
{
    for(int j=0;j<res[0].size();j++)
    {
        matrix[i][j] = res[i][j];
    }
}
return ;
}
};
posted @ 2020-11-20 16:57  诗和远方*  阅读(347)  评论(0编辑  收藏  举报