230724 신고 결과 받기

Jongleee·2023년 7월 24일
0

TIL

목록 보기
319/576
public int[] solution(String[] idList, String[] report, int k) {
	Map<String, Set<String>> reporterInfoMap = new HashMap<>();
	Map<String, Integer> reportedCountInfoMap = new HashMap<>();
	Set<String> reportSet = new HashSet<>(Arrays.asList(report));

	for (String reportInfo : reportSet) {
		String reporter = reportInfo.split(" ")[0];
		String reported = reportInfo.split(" ")[1];

		reporterInfoMap.computeIfAbsent(reporter, key -> new HashSet<>()).add(reported);
		reportedCountInfoMap.put(reported, reportedCountInfoMap.getOrDefault(reported, 0) + 1);
	}

	int[] answer = new int[idList.length];
	for (int i = 0; i < idList.length; i++) {
		String user = idList[i];
		Set<String> reportsReceived = reporterInfoMap.getOrDefault(user, new HashSet<>());

		for (String reported : reportsReceived) {
			if (reportedCountInfoMap.getOrDefault(reported, 0) >= k) {
				answer[i]++;
			}
		}
	}
	return answer;
}

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

1개의 댓글

comment-user-thumbnail
2023년 7월 24일

정보 감사합니다.

답글 달기