I want to print this array [1,2,3,4]
as a 2D array [[1,2],[3,4]]
. This is the code. I am not getting these line
vector<int> aux(&original[i], &original[i+n]);
ans.push_back(aux);
how the syntax of 2D vector is working? Here is the function code?
class Solution {
public:
vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {
vector<vector<int>> ans;
int p = original.size();
if(m*n != p)
return ans;
for(int i=0;i<p;i+=n){
vector<int> aux(&original[i], &original[i+n]);
ans.push_back(aux);
}
return ans;
}
};