Skip to content

Commit

Permalink
Create 2022_Convert_1D_Array_Into_2D_Array.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing-avil authored Sep 1, 2024
1 parent 9efefdf commit 472fafd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 2022_Convert_1D_Array_Into_2D_Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ███████╗ █████╗ ███╗ ██╗ ██████╗ █████╗ ██████╗ ██████╗ ██╗ ██╗
// ██╔════╝ ██╔══██╗ ████╗ ██║ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██║ ██║
// ███████╗ ███████║ ██╔██╗ ██║ ██║ ██║ ███████║ ██████╔╝ ██████╔╝ ███████║
// ╚════██║ ██╔══██║ ██║╚██╗██║ ██║ ██║ ██╔══██║ ██╔═██╗ ██╔══██╗ ██╔══██║
// ███████║ ██║ ██║ ██║ ╚████║ ██████╔╝ ██║ ██║ ██║ ██╗ ██████╔╝ ██║ ██║
// ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
#pragma GCC optimize("Ofast", "inline", "ffast-math", "unroll-loops","no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native", "f16c")
auto init = []() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 'c';
}();
class Solution {
public:
vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {
if(original.size() != m*n){
return {};
}
int k=0;
vector<vector<int>> ans(m, vector<int>(n));
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
ans[i][j]=original[k++];
}
}
return ans;
}
};

0 comments on commit 472fafd

Please sign in to comment.