프로그래머스 | 신고 결과 받기 | 2022 카카오 블라인드 | Javascript
1194 단어 JavaScript프로그래머스JavaScript
https://programmers.co.kr/learn/courses/30/lessons/92334
문제
프로그래머스에 올라온 2022 카카오 블라인드 중 신고 결과 받기 문제를 자바스크립트로 풀었습니다.
전체 유저 목록 id_list,
유저가 유저를 신고한 내용 report,
정지되는 신고건수 k를 받았을때
정지되었다고 받은 메일의 개수 배열을 반환하는 문제입니다.
코드
function solution(id_list, report, k) {
let report_info = {};
let mail_count = {};
for (let command of report) {
const [sender, receiver] = command.split(" ");
if (report_info[receiver] && report_info[receiver].includes(sender))
continue;
report_info[receiver] = [...(report_info[receiver] || []), sender];
}
for (let id of id_list) {
if (report_info[id] && report_info[id].length >= k) {
for (let id2 of report_info[id])
mail_count[id2] = mail_count[id2] ? mail_count[id2] + 1 : 1;
}
}
const answer = id_list.map((id) => mail_count[id] || 0);
return answer;
}
풀이
function solution(id_list, report, k) {
let report_info = {};
let mail_count = {};
for (let command of report) {
const [sender, receiver] = command.split(" ");
if (report_info[receiver] && report_info[receiver].includes(sender))
continue;
report_info[receiver] = [...(report_info[receiver] || []), sender];
}
for (let id of id_list) {
if (report_info[id] && report_info[id].length >= k) {
for (let id2 of report_info[id])
mail_count[id2] = mail_count[id2] ? mail_count[id2] + 1 : 1;
}
}
const answer = id_list.map((id) => mail_count[id] || 0);
return answer;
}
신고 내용 report를 for문으로 돌면서 중복이 안되게끔
{ 신고받은사람 : [신고 한사람] }의 데이터를 만듭니다.
신고한사람이 k이상이면 정지된 사람이고, 이 때 신고한사람들의 mail_count를 1개 올립니다.
Author And Source
이 문제에 관하여(프로그래머스 | 신고 결과 받기 | 2022 카카오 블라인드 | Javascript), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@dishate/프로그래머스-2022-카카오-블라인드-신고-결과-받기-Javascript저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)