class Solution {
    public int[] solution(int N, int[] stages) {
        int[] answer = new int[N];
        int[] fail = new int[N+1];
        double[] fRate = new double[N];
        int players = stages.length;
            
        for(int stage : stages) { fail[stage-1]++; }

        for(int i=0; i<N; i++) {
            if(players==0) { continue; }
            
            fRate[i] = (double)fail[i]/players;
            players -= fail[i];
        }
        
        for(int i=0; i<N; i++) {
            double max = -1;
            int index = 0;
            for(int j=0; j<N; j++) {
                if(fRate[j]>max) {
                    max = Math.max(fRate[j], max);
                    index = j;
                }
            }
            
            fRate[index] = -2;
            answer[i] = index+1; 
        }
        
        return answer;
    }
}

'Problem Solving > Programmers' 카테고리의 다른 글

[Level 1] 3진법 뒤집기  (0) 2022.03.23
[Level 1] 약수의 개수와 덧셈  (0) 2022.03.23
[Level 1] 폰켓몬  (0) 2022.03.23
[Level 1] 체육복  (0) 2022.03.23
[Level 1] 모의고사  (0) 2022.03.23