We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 047d85b commit 44419faCopy full SHA for 44419fa
C++/Reshape-the-Matrix.cpp
@@ -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