티스토리 뷰

728x90
SMALL

풀이

function solution(N, stages) {
    let arrival_not_clear, arrival;
    let arr=[];
    for(let i=0;i<N;i++){
        arrival_not_clear=0;
        arrival=0;
        for(let j=0;j<stages.length;j++){
            if(i+1<=stages[j]){
                arrival++;
            }
            if(i+1===stages[j]){
                arrival_not_clear++;
            }
        }
        arr.push(arrival_not_clear/arrival);
    }
    arr=arr.map((percent,index)=>(
         {index:index+1,percent}
    ));
    arr.sort(comparePercent);
    let ans=[];
    for(let i=0;i<N;i++){
        ans.push(arr[i].index);
    }
    return ans;
    function comparePercent(a, b){
        if(a.percent>b.percent) return -1;
        else if(a.percent<b.percent) return 1;
        else return a.index-b.index;
    }
}
728x90
LIST
댓글
공지사항