public int[] solution(String[] idList, String[] report, int k) {
Map<String, Set<String>> reporterInfoMap = new HashMap<>();
Map<String, Integer> reportedCountInfoMap = new HashMap<>();
Set<String> reportSet = new HashSet<>(Arrays.asList(report));
for (String reportInfo : reportSet) {
String reporter = reportInfo.split(" ")[0];
String reported = reportInfo.split(" ")[1];
reporterInfoMap.computeIfAbsent(reporter, key -> new HashSet<>()).add(reported);
reportedCountInfoMap.put(reported, reportedCountInfoMap.getOrDefault(reported, 0) + 1);
}
int[] answer = new int[idList.length];
for (int i = 0; i < idList.length; i++) {
String user = idList[i];
Set<String> reportsReceived = reporterInfoMap.getOrDefault(user, new HashSet<>());
for (String reported : reportsReceived) {
if (reportedCountInfoMap.getOrDefault(reported, 0) >= k) {
answer[i]++;
}
}
}
return answer;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/92334
정보 감사합니다.