-
[JS] 실패율이노베이션 캠프/3주차_알고리즘 2023. 6. 21. 17:27
문제
https://school.programmers.co.kr/learn/courses/30/lessons/42889
문제 풀이
function solution(N, stages) { let result = []; // 1) 결과 값 저장할 변수 // 2) for문 사용하여 주어진 스테이지의 수만큼 반복 for (let i=1; i<=N; i++) { let success = stages.filter((s) => s >= i).length; // 2-1) 스테이지에 도달한 플레이어 수 let fails = stages.filter((s) => s === i).length; // 2-2) 아직 클리어하지 못한 플레이어의 수 result.push([i, fails/success]); } // 3) 실패율로 배열 정렬 result.sort((a,b) => b[1] - a[1]); return result.map((r) => r[0]); }
728x90'이노베이션 캠프 > 3주차_알고리즘' 카테고리의 다른 글
[JS] 체육복 (0) 2023.06.21 [JS] 크레인 인형뽑기 게임 (0) 2023.06.21 [JS] 다트 게임 (1차) (0) 2023.06.21 [JS] 비밀지도 (0) 2023.06.21 [JS] 폰켓몬 (0) 2023.06.21