package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/convert-1d-array-into-2d-array/
 */
public class Problem2022 {
    public int[][] construct2DArray(int[] original, int m, int n) {
        // TODO
        return null;
    }

    private static void print(int[][] a) {
        for (int[] i : a) {
            System.out.println(Arrays.toString(i));
        }
    }

    public static void main(String[] args) {
        Problem2022 prob = new Problem2022();
        print(prob.construct2DArray(new int[]{1,2,3,4}, 2, 2)); // [[1,2],[3,4]]
        print(prob.construct2DArray(new int[]{1,2,3}, 1, 3)); // [[1,2,3]]
        print(prob.construct2DArray(new int[]{1,2}, 1, 1)); // []
        print(prob.construct2DArray(new int[]{3}, 1, 2)); // []

    }
}

@@ -16,34 +16,8 @@
 e;%0A%0A
-import java.util.Arrays;%0A%0A
 /**%0A
@@ -192,86 +192,123 @@
     
-// TODO%0A        return null;%0A
+if (m * n != original.length) %7B%0A            return new int%5B%5D%5B%5D%7B%7D;%0A   
     
+ 
 %7D
-%0A
 %0A    
-private static void print(
+    int%5B%5D%5B%5D answer = new 
 int%5B
+m
 %5D%5B
-%5D a) %7B
+n%5D;
 %0A   
@@ -316,474 +316,199 @@
     
-for (int%5B%5D i : a) %7B%0A            System.out.println(Arrays.toString(i));%0A        %7D%0A
+int index = 0;%0A        for (int i = 0; i %3C m; i++) %7B%0A  
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem2022 prob = new Problem2022();%0A        print(prob.construct2DArray(new int%5B%5D%7B1,2,3,4%7D, 2, 2)); // %5B%5B1,2%5D,%5B3,4%5D%5D%0A        print(prob.construct2DArray(new int%5B%5D%7B1,2,3%7D, 1, 3)); // %5B%5B1,2,3%5D%5D%0A        print(prob.construct2DArray(new int%5B%5D%7B1,2%7D, 1, 1)); // %5B%5D%0A        print(prob.construct2DArray(new int%5B%5D%7B3%7D, 1, 2)); // %5B%5D%0A
+  for (int j = 0; j %3C n; j++) %7B%0A                answer%5Bi%5D%5Bj%5D = original%5Bindex++%5D;%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 2022