Skip to content

Commit b32f7d5

Browse files
authored
Merge pull request neetcode-gh#3574 from Tetsuya3850/patch-14
Create 2610-convert-an-array-into-a-2d-array-with-conditions.java
2 parents f5488aa + f849c8f commit b32f7d5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public List<List<Integer>> findMatrix(int[] nums) {
3+
Map<Integer, Integer> count = new HashMap<>();
4+
List<List<Integer>> res = new ArrayList<>();
5+
6+
for (int n : nums) {
7+
int row = count.getOrDefault(n, 0);
8+
if (res.size() == row) {
9+
res.add(new ArrayList<>());
10+
}
11+
res.get(row).add(n);
12+
count.put(n, count.getOrDefault(n, 0) + 1);
13+
}
14+
15+
return res;
16+
}
17+
}

0 commit comments

Comments
 (0)