Skip to content

Commit d384211

Browse files
committed
Runtime: 4 ms (Top 59.22%) | Memory: 55.50 MB (Top 5.02%)
1 parent ee0e7b6 commit d384211

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Runtime: 4 ms (Top 59.22%) | Memory: 55.50 MB (Top 5.02%)
2+
3+
class Solution {
4+
public int[][] construct2DArray(int[] original, int m, int n) {
5+
if (original.length != m * n) return new int[0][];
6+
7+
int[][] ans = new int[m][n];
8+
int currRow = 0, currCol = 0;
9+
10+
for (int num : original) {
11+
ans[currRow][currCol++] = num;
12+
13+
if (currCol == n) {
14+
currCol = 0;
15+
currRow++;
16+
}
17+
}
18+
19+
return ans;
20+
}
21+
}
22+
23+
// TC: O(n), SC: O(m * n)

0 commit comments

Comments
 (0)