题目

image.pngimage.png

题解

  1. class Solution {
  2. public int[][] construct2DArray(int[] original, int m, int n) {
  3. int size = original.length ;
  4. if(size != m * n) return new int[0][0];
  5. int[][] res = new int[m][n];
  6. int i = 0, row = 0,col = 0;
  7. while( i < size ) {
  8. col = i % n;
  9. row = i / n;
  10. res[row] [col] = original[i++];
  11. }
  12. return res;
  13. }
  14. }