import java.util.*;
class Solution {
public int[] solution(int N, int[] stages) {
int[] answer = new int[N];
Map<Integer,Double> map = new HashMap<>();
for(int i=1; i<=N; i++){
int cnt=0,num=0;
for(int j=0; j<stages.length; j++){
if(stages[j] >= i) cnt++;
if(stages[j] == i) num++;
}
if(cnt==0 && num==0) cnt=1;
double fail = (double) num/cnt;
map.put(i,fail);
}
//내림차순 정렬.
for(int i=0; i<N; i++){
double max = -1;
int key=0;
for(int x : map.keySet()){
if(max < map.get(x)){
max = map.get(x);
key = x;
}
}
answer[i] = key;
map.remove(key);
}
return answer;
}
}
처음에 level과 실패율을 가지는 객체를 하나 만들어서 Comparable<>로 편하게 풀려고했는데 타입이 달라서 에러가 뜨더라..