leetcode 566. 重塑矩阵
作者:互联网
题解
这次又是简单题 题目还是比较简单的,就喜欢做简单题!
也需要一定的思维吧
题解
官方题解
代码
class Solution {
public:
vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {
if(nums.empty()){
return nums;
}
int row = nums.size();
int column = nums[0].size();
vector<vector<int>>d(r,vector<int>(c));
if(r*c != row*column || nums.empty()){
return nums;
}
for(int i = 0; i < row*column; i++){
d[i/c][i%c] = nums[i/column][i%column];
}
return d;
}
};
标签:nums,int,题解,566,column,vector,重塑,leetcode,row 来源: https://blog.csdn.net/amnesia_mint/article/details/113831405