class Solution {
public:
vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {
vector<vector<int>> res(r);
int m=nums.size();
int n = nums[0].size();
if(m*n!=r*c)return nums;
int row=0,col = 0,count = 0;
for(int i=0;i<m;i++)
{
for(int j = 0;j<n;j++)
{
if(count==c)
{
count = 0;
row++;
}
res[row].push_back(nums[i][j]);
count++;
}
}
return res;
}
};