int[] answer = new int[id_list.length];
Map<String, Set<String>> reportMap = new HashMap<>();
for(int i = 0; i < report.length; i++){
String[] cur = report[i].split(" ");
if(reportMap.containsKey(cur[1])){
reportMap.get(cur[1]).add(cur[0]);
}else{
Set<String> newList = new HashSet<>();
newList.add(cur[0]);
reportMap.put(cur[1], newList);
}
}
for (String key : reportMap.keySet()) {
Set<String> curSet = reportMap.get(key);
if(curSet.size() >= k){
curSet.forEach(item -> {
int idx = Arrays.asList(id_list).indexOf(item);
answer[idx]++;
});
}
}
return answer;
report에서
신고자, 신고당한사람을 분리 후 분류하고 이때 Set을 사용하면 좀 더 쉽게 분류가능
Set은 중복을 허용 안한다.
그 다음 K가 넘는 리스트만 ++ 해주면된다.