-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprblem1
29 lines (28 loc) · 884 Bytes
/
prblem1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public List<List<Integer>> findMatrix(int[] v) {
Map<Integer, Integer> um = new HashMap<>();
for (int i : v) {
um.put(i, um.getOrDefault(i, 0) + 1);
}
List<List<Integer>> ans = new ArrayList<>();
while (!um.isEmpty()) {
List<Integer> temp = new ArrayList<>();
List<Integer> toErase = new ArrayList<>();
for (Map.Entry<Integer, Integer> entry : um.entrySet()) {
int f = entry.getKey();
int s = entry.getValue();
temp.add(f);
s--;
if (s == 0) {
toErase.add(f);
}
um.put(f, s);
}
ans.add(temp);
for (int i : toErase) {
um.remove(i);
}
}
return ans;
}
}