코딩테스트 : 신고 결과 받기

김하영·2022년 4월 13일
0

https://programmers.co.kr/learn/courses/30/lessons/92334

아직 미완성...

import lombok.extern.slf4j.Slf4j;

import java.util.*;

@Slf4j
public class Solution {

    public static int[] solution(String[] id_list, String[] reportArr, int report_count) {

        int[] answer = new int[id_list.length];

        Map<String, Integer> idReportCountMap = new HashMap<>();

        for (String report : reportArr) {
            String[] report_ids = report.split(" ");
            for (String report_id : report_ids) {
                idReportCountMap.merge(report_id, 1, Integer::sum);
            }
        }

        List<String> stopTargetList = new ArrayList<>();

        for (String id : id_list) {
            if (idReportCountMap.get(id) >= report_count) {
                stopTargetList.add(id);
            }
        }

        for (int i = 0; i < reportArr.length; i++) {
            List<String> report_ids = Arrays.stream(reportArr[i].split(" ")).toList();
            int answerCount = 0;
            for (String report_id : report_ids) {
                if (stopTargetList.contains(report_id)) {
                    answerCount++;
                }
            }
            answer[i] = answerCount;
        }

        return answer;
    }

    public static void main(String[] args) {
        String[] id_list = {"muzi", "frodo", "apeach", "neo"};
        String[] report = {"muzi frodo", "apeach frodo", "frodo neo", "muzi neo", "apeach muzi"};
        int report_count = 2;
        solution(id_list, report, report_count);
    }
}
profile
Back-end Developer

0개의 댓글