```
vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {
int col = nums[0].size();
if (nums.size()*col != r*c) return nums;
vector<vector<int>> res(r, vector<int>(c));
for (int i = 0; i < r*c; ++i) res[i/c][i%c] = nums[i/col][i%col];
return res;
}
```