Posted on

Description

Submission

class Solution {
public:
    vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {
        if(original.size() != m * n) return {};
        vector<vector<int>> rets(m, vector<int>(n));
        
        for(int i = 0; i < m; ++i) {
            for(int j = 0; j < n; ++j) {
                rets[i][j] = original[i * n + j];
            }
        }

        return rets;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *