2022. Convert 1D Array Into 2D Array 發表於 2023-02-13 | 分類於 leetcode problemsolution123456789101112131415class Solution {public: vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) { vector<vector<int>> ret; if(original.size() != m*n) return ret; ret = vector<vector<int>>(m,vector<int>(n,0)); int k =0 , c = original.size(); for(int i=0;i<m;i++){ for(int j = 0;j<n;++j){ ret[i][j] = original[k++]; } } return ret; }}; analysis time complexity O(n) space complexity O(1)