题目:
思路:先判断元素总数,不同则返回原数组
至于不同位置的元素则根据每行的个数即列数来判断
class Solution {
public:
vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {
int m = nums.size();
int n = nums[0].size();
int count = m * n;
if(count != r * c) return nums;
vector<vector<int>> res(r);
for(int i = 0;i < count;i++)
res[i / c][i % c] = nums[i / n][i % n];
return res;
}
};