Skip to content

Commit f897533

Browse files
committed
feat: java solution for leetcode-2022
1 parent f557cdd commit f897533

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Convert 1D array to 2D array.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int[][] construct2DArray(int[] original, int m, int n) {
3+
if(original.length != m*n){
4+
return new int [0][0];
5+
}
6+
int[][] result = new int[m][n];
7+
for(int i=0; i<m ; i++){
8+
for(int j=0; j<n ; j++){
9+
result[i][j] = original[i*n + j];
10+
}
11+
}
12+
return result;
13+
}
14+
}

0 commit comments

Comments
 (0)