728x90
반응형
SMALL
[프로그래머스] Lev 2. 신고 결과 받기
https://school.programmers.co.kr/learn/courses/30/lessons/92334
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr


걸린시간: 22분
import java.io.IOException;
import java.util.*;
class Solution {
static Map<String, Integer> reportCounting = new HashMap<>();
static Map<String, Information> info = new HashMap<>();
public static int[] solution(String[] id_list, String[] report, int k) {
int[] answer = new int[id_list.length];
setUp(id_list);
registReport(report);
for (int i = 0; i < id_list.length; i++) {
Set<String> repostList = info.get(id_list[i]).reportList;
int cnt = 0;
for (String name : repostList){
if (reportCounting.get(name)>=k){
cnt++;
}
}
answer[i]=cnt;
}
return answer;
}
static class Information {
private Set<String> reportList = new HashSet<>();
public void report(String name){
reportList.add(name);
}
}
static void setUp(String[] id_list){
for (int i = 0; i < id_list.length; i++) {
reportCounting.put(id_list[i],0);
info.put(id_list[i],new Information());
}
}
static void registReport(String[] report){
for (int i = 0; i < report.length; i++) {
String[] str = report[i].split(" ");
String reporter = str[0];
String reported = str[1];
//이미 신고한적이 있다면 카운팅 안한다.
if (!info.get(reporter).reportList.contains(reported)){
info.get(reporter).report(reported);
reportCounting.put(reported, reportCounting.get(reported)+1);
}
}
}
}728x90
반응형
LIST
'Personal Studying~ > 자바문제 풀어보기' 카테고리의 다른 글
| [프로그래머스] Lev 2. 괄호 회전하기 (1) | 2025.09.24 |
|---|---|
| [프로그래머스] Lev 2. 행렬 테두리 회전하기 (0) | 2025.09.23 |
| [프로그래머스] Lev 2. 성격 유형 검사하기 (0) | 2025.09.23 |
| [재귀, 백트래킹] 연산자 끼워넣기(BOJ 14888) (1) | 2025.05.15 |
| [프로그래머스]lev2 순위검색 (0) | 2023.09.20 |