In fact, it is a reshaping matrix algorithm, the specific implementation is as follows
vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {
int m=mat.size();
int n=mat[0].size();
if(m*n!=r*c)
{
return mat;
}
vector<vector<int>> ans(r, vector<int>(c));
for(int i=0;i<m*n;i++){
ans[i/c][i%c]=mat[i/n][i%n];
}
return ans;
}
It is to convert the A[x][y] matrix into B[]m[n], where x*y=m*n