Skip to content

Commit 44419fa

Browse files
added leetcode 566 (#193)
1 parent 047d85b commit 44419fa

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

C++/Reshape-the-Matrix.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {
4+
if(mat.size()*mat[0].size() != r*c) return mat;
5+
vector<int> v;
6+
for(int i=0;i<mat.size();i++){
7+
for(int j=0;j<mat[0].size();j++){
8+
v.push_back(mat[i][j]);
9+
}
10+
}
11+
int k=0;
12+
vector<vector<int>> vnew;
13+
vector<int> input;
14+
for(int i=0;i<r;i++){
15+
for(int j=0;j<c;j++){
16+
input.push_back(v[k++]);
17+
}
18+
vnew.push_back(input);
19+
input.clear();
20+
}
21+
return vnew;
22+
}
23+
};

0 commit comments

Comments
 (0)