class Solution {
public:
vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {
if(mat.size()*mat[0].size() != r * c) return mat;
vector<vector<int>> v(r,vector<int>(c,0));
int row = 0,col = 0;
for(int i = 0; i < mat.size();i++)
{
for(int j = 0; j < mat[0].size();j++)
{
if(col == c)
{
row += 1;
col = 0;
}
v[row][col] = mat[i][j];
col++;
}
}
return v;
}
};
leetcode每日一题第110天
最新推荐文章于 2024-07-20 09:21:06 发布