1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00

java: add «2022. Convert 1D Array Into 2D Array»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-09-01 13:53:04 +02:00
parent f848a7b9c7
commit 4e73b65849
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,15 @@
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;
}
}