💡 풀이
- cntMap : 유저별 신고 당한 횟수 카운트
- idMap : 유저별 신고한 ID 리스트로 넣기
- reportSet : report 중복 제거
- cntMap의 value를 확인하면서 k 이상 신고 당한 유저를 리스트에 넣기
- idMap을 돌면서 유저가 신고한 ID 리스트 중에 정지당한 유저가 있으면 resCnt++
import java.util.*;
class Solution {
public int[] solution(String[] id_list, String[] report, int k) {
HashMap<String, Integer> cntMap = new HashMap<>();
HashMap<String, ArrayList<String>> idMap = new HashMap<>();
HashSet<String> reportSet = new HashSet<>();
for(int i = 0; i<id_list.length; i++){
idMap.put(id_list[i], new ArrayList<String>());
}
for(String rep : report){
reportSet.add(rep);
}
for(String rep : reportSet){
String[] input = rep.split(" ");
cntMap.put(input[1], cntMap.getOrDefault(input[1], 0) + 1);
idMap.get(input[0]).add(input[1]);
}
ArrayList<String> banned = new ArrayList<>();
for(String cnt : cntMap.keySet()){
if (cntMap.get(cnt) >= k) banned.add(cnt);
}
int[] answer = new int[id_list.length];
for(int i = 0; i<id_list.length; i++){
ArrayList<String> check = idMap.get(id_list[i]);
int resCnt = 0;
for(String c : check){
if (banned.contains(c)) resCnt++;
}
answer[i] = resCnt;
}
return answer;
}
}