方法一:模拟
class Solution {
public int[][] construct2DArray(int[] original, int m, int n) {
if (m * n != original.length) return new int[0][0];
int rowIdx = 0, colIdx = 0;
int[][] res = new int[m][n];
for (int i = 0; i < original.length; i++) {
res[rowIdx][colIdx] = original[i];
if (++colIdx == n) {
colIdx = 0;
rowIdx++;
}
}
return res;
}
}