프로그래머스 > 코딩테스트 연습 > 2022 KAKAO BLIND RECRUITMENT > 신고 결과 받기
function solution(id_list, report, k) {
let answer = new Array();
let list = new Array();
let count = new Array();
for (let i = 0; i < id_list.length; i++) {
list[id_list[i]] = new ID();
count[id_list[i]] = 0;
answer[i] = 0;
}
for (let i = 0; i < report.length; i++) {
let s = report[i].split(" ");
if (list[s[0]].check(s[1])) continue;
list[s[0]].add(s[1]);
count[s[1]]++;
}
for (let i = 0; i < id_list.length; i++) {
let arr = list[id_list[i]].arr;
for (let j = 0; j < arr.length; j++) {
if (count[arr[j]] >= k) answer[i]++;
}
}
return answer;
}
class ID {
constructor(){
this.arr = new Array();
}
add = function(name) {
this.arr.push(name);
}
check = function(name) {
if (this.arr.indexOf(name) != -1) return true;
return false;
}
}
let answer = new Array(); let list = new Array(); let count = new Array(); for (let i = 0; i < id_list.length; i++) { list[id_list[i]] = new ID(); count[id_list[i]] = 0; answer[i] = 0; }
for (let i = 0; i < report.length; i++) { let s = report[i].split(" "); -- 중략 -- }
for (let i = 0; i < report.length; i++) { -- 중략 -- if (list[s[0]].check(s[1])) continue; list[s[0]].add(s[1]); count[s[1]]++; }
for (let i = 0; i < id_list.length; i++) { let arr = list[id_list[i]].arr; for (let j = 0; j < arr.length; j++) { if (count[arr[j]] >= k) answer[i]++; } }