Skip to content

Commit 6c3a20a

Browse files
authored
Create 2022. Convert 1D Array Into 2D Array (#572)
2 parents e15e20e + b22c99d commit 6c3a20a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

2022. Convert 1D Array Into 2D Array

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {
4+
vector<vector<int>>ans(m, vector<int>(n));
5+
int x=0;
6+
if(m*n!=original.size()){
7+
8+
return {};
9+
}
10+
for(int i=0; i<m; i++){
11+
for(int j=0; j<n; j++){
12+
ans[i][j]= original[x++];
13+
}
14+
}
15+
return ans;
16+
17+
}
18+
};

0 commit comments

Comments
 (0)