```
class Solution {
public:
vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {
if(nums[0].size()*nums.size()!=r*c)
return nums;
vector<vector<int>> result(r,vector<int>(c));
int n=nums[0].size();
for(int i=0; i<c*r;i++)
result[i/c][i%c]=nums[i/n][i%n];
return result;
}
};
```