- 문제
- 게시판 이용자들간의 신고 누적을 통한 이용 정지를 하고, 이용 정지된 신고자들에게 확인 이메일을 보냄, 이용자들의 이메일 수신 횟수를 리턴하라
- 요소 : 이용자리스트, 신고목록, 정지기준횟수
- 조건 : 같은 이용자를 중복 신고는 가능하지만 1회만 인정, 자기 자신을 신고하지는 못함
- 수도코드
- 결과
function solution(id_list, report, k) {
let repo = [...new Set(report)];
let warn = Array(id_list.length).fill(0);
let mail = Array(id_list.length).fill(0);
let out = [];
let list = Array(id_list.length).fill([]);
for (let a of repo) {
let c = a.split(" ")[1];
warn[id_list.indexOf(c)] += 1;
if (warn[id_list.indexOf(c)] >= k) {
out.push(id_list.indexOf(c))
}
}
for (let a of repo) {
let b = a.split(" ")[0];
let c = a.split(" ")[1];
if (out.includes(id_list.indexOf(c))) {
mail[id_list.indexOf(b)] += 1;
}
}
return mail;
}
- 레퍼런스
function solution(id_list, report, k) {
let reports = [...new Set(report)].map(a=>{return a.split(' ')});
let counts = new Map();
for (const bad of reports){
counts.set(bad[1],counts.get(bad[1])+1||1)
}
let good = new Map();
for(const report of reports){
if(counts.get(report[1])>=k){
good.set(report[0],good.get(report[0])+1||1)
}
}
let answer = id_list.map(a=>good.get(a)||0)
return answer;
}
- map와 set을 활용한 풀이, 레퍼런스 자체를 공부해 봐야겠다