-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReceiveReportResult.java
More file actions
42 lines (34 loc) · 1.32 KB
/
ReceiveReportResult.java
File metadata and controls
42 lines (34 loc) · 1.32 KB
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
34
35
36
37
38
39
40
41
42
package algorithm.complexproblem;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class ReceiveReportResult {
public static int[] solution(String[] id_list, String[] report, int k) {
int[] answer = new int[id_list.length];
Map<String, HashSet<String>> userBlackLists = new HashMap<>();
Map<String, Integer> reportedList = new HashMap<>();
for (int i = 0; i < id_list.length; i++) {
HashSet<String> blackUsers = new HashSet<>();
userBlackLists.put(id_list[i], blackUsers);
reportedList.put(id_list[i], 0);
}
for (String s : report) {
String[] temp = s.split(" ");
String reportingID = temp[0];
String reportedID = temp[1];
userBlackLists.get(reportedID).add(reportingID);
}
for (String reportedUser : userBlackLists.keySet()) {
HashSet<String> userForSend = userBlackLists.get(reportedUser);
if (userForSend.size() >= k) {
for (String userId : userForSend) {
reportedList.put(userId, reportedList.get(userId) + 1);
}
}
}
for (int i = 0; i < id_list.length; i++) {
answer[i] = reportedList.get(id_list[i]);
}
return answer;
}
}