- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1817.java
33 lines (31 loc) · 1.06 KB
/
_1817.java
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
30
31
32
33
packagecom.fishercoder.solutions.secondthousand;
importjava.util.HashMap;
importjava.util.HashSet;
importjava.util.Map;
importjava.util.Set;
importjava.util.TreeMap;
publicclass_1817 {
publicstaticclassSolution1 {
publicint[] findingUsersActiveMinutes(int[][] logs, intk) {
Map<Integer, Set<Integer>> map = newHashMap<>();
for (int[] log : logs) {
intuser = log[0];
if (!map.containsKey(user)) {
map.put(user, newHashSet<>());
}
Set<Integer> set = map.get(user);
set.add(log[1]);
}
int[] result = newint[k];
TreeMap<Integer, Integer> treeMap = newTreeMap<>();
for (intkey : map.keySet()) {
intuam = map.get(key).size();
treeMap.put(uam, treeMap.getOrDefault(uam, 0) + 1);
}
for (intkey : treeMap.keySet()) {
result[key - 1] = treeMap.get(key);
}
returnresult;
}
}
}