分析
按照题意模拟过程
C++ 代码
class Solution {
public:
vector<vector<int>> ans;
vector<int> temp;
vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {
int n=nums.size(),m=nums[0].size();
if(n*m!=r*c) return nums;
for(auto row:nums)
{
for(auto x:row)
{
temp.push_back(x);
if(temp.size()==c)
{
ans.push_back(temp);
temp.clear();
}
}
}
return ans;
}
};