要求:rt
思路:
class Solution {
public:
vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {
int rr=mat.size(),vv=mat[0].size();
if(r*c!=rr*vv)return mat;
vector<vector<int>> ans(r,vector<int>(c));
int index=0;
for(int i=0;i<rr;++i){
for(int j=0;j<vv;++j){
ans[index/c][index%c]=mat[i][j];
++index;
}
}
return ans;
}
};