mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 18:07:32 +01:00
16 lines
319 B
Java
16 lines
319 B
Java
|
class Solution {
|
||
|
public int[][] construct2DArray(int[] original, int m, int n) {
|
||
|
if (original.length != m * n) {
|
||
|
return new int[0][0];
|
||
|
}
|
||
|
|
||
|
var array = new int[m][n];
|
||
|
for (int i = 0; i < m * n; ++i) {
|
||
|
int y = i / n, x = i % n;
|
||
|
array[y][x] = original[i];
|
||
|
}
|
||
|
|
||
|
return array;
|
||
|
}
|
||
|
}
|