코딩블로그
프로그래머스 Lv 1- 2022 KAKAO BLIND RECRUITMENT - 신고 결과 받기 JAVA 본문
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/92334
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
import java.util.*;
class Solution {
public int[] solution(String[] id_list, String[] report, int k) {
//유저가 신고한 ID를 가져올 수 있는 자료구조 사용하기
HashMap<String, List<String>> total = new HashMap<>();
HashMap<String, Integer> reportCount = new HashMap<>();
int[] mail = new int[id_list.length];
//초기화
for (int i =0; i <id_list.length; i++) {
total.put(id_list[i], new ArrayList<>());
}
for (int i =0; i <id_list.length; i++) {
reportCount.put(id_list[i], 0);
}
//report 정리하기
for (String a : report) {
String[] temp = a.split(" ");
List<String> tem = total.get(temp[0]);
if (tem.contains(temp[1])) {
continue;
} else {
int count = reportCount.get(temp[1]);
count += 1;
reportCount.put(temp[1],count);
tem.add(temp[1]);
total.put(temp[0], tem);
}
}
for (int i = 0; i < id_list.length; i++) {
List<String> tem = total.get(id_list[i]);
for (String t : tem) {
if (reportCount.get(t) >= k) {
mail[i] += 1;
}
}
}
int[] answer = mail;
return answer;
}
}
728x90