forked from rising-entropy/Leetcode-Questions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinding_Users.java
32 lines (32 loc) · 1.04 KB
/
Finding_Users.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
import java.util.*;
class Solution {
public static void main(String[] args) {
Solution sol = new Solution();
int logs[][] = {{0,5 },{1,2},{0,2},{0,5},{1,3}};
int k = 5;
System.out.println(sol.findingUsersActiveMinutes(logs, k));;
}
public int[] findingUsersActiveMinutes(int[][] logs, int k) {
int answers[] = new int[k];
Arrays.fill(answers,0);
HashMap<Integer,HashSet<Integer>> hm = new HashMap<>();
for(int i=0;i<logs.length;i++){
int id = logs[i][0];
int time = logs[i][1];
if(hm.containsKey(id)){
HashSet<Integer> hs = hm.get(id);
hs.add(time);
hm.put(id, hs);
}
else{
HashSet<Integer> hs = new HashSet<Integer>();
hs.add(time);
hm.put(id, hs);
}
}
for(Map.Entry<Integer,HashSet<Integer>> entry :hm.entrySet()){
answers[entry.getValue().size()]++;
}
return answers;
}
}