- 난이도: Lv1
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/92334
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/1/신고 결과 받기
풀이 시간 : 45분
import java.util.*;
class Solution {
public int[] solution(String[] id_list, String[] report, int k) {
int[] answer = new int[id_list.length];
Map<String, Set<String>> reportMap = new HashMap<>();
Map<String, Integer> userIndexMap = new HashMap<>();
for (int i = 0; i < id_list.length; i++) {
reportMap.put(id_list[i], new HashSet<>());
userIndexMap.put(id_list[i], i);
}
for (String entry : report) {
String[] parts = entry.split(" ");
reportMap.get(parts[1]).add(parts[0]);
}
for (String user : id_list) {
Set<String> reporters = reportMap.get(user);
if (reporters.size() >= k) {
for (String reporter : reporters) {
answer[userIndexMap.get(reporter)]++;
}
}
}
return answer;
}
}