2022.cpp (374B)
1 class Solution { 2 public: 3 vector<vector<int>> construct2DArray(const vector<int> &original, int n, int m) const { 4 vector<vector<int>> res(n); 5 6 if (m * n != size(original)) return {}; 7 for (int i = 0, k = 0; i < n; ++i) { 8 res[i] = vector(begin(original) + i * m, begin(original) + (i + 1) * m); 9 } 10 11 return res; 12 } 13 };