Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {
- int row = mat.size(), col = mat[0].size();
- if(r*c != row*col)
- return mat;
- vector<vector<int>> nmat;
- for(int i=0; i<r; i++){
- vector<int> tmp;
- for(int j=0; j<c; j++){
- int idx = i*c+j;
- tmp.push_back(mat[idx/col][idx%col]);
- }
- nmat.push_back(tmp);
- }
- return nmat;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement