알고리즘은 맞는데 시간이 너무 오래걸림
import java.util.*;
class Point implements Comparable<Point>{
int stage;
Float rate;
Point(int s, float r){
this.stage = s;
this.rate= r;
}
@Override
public int compareTo(Point x){
if(x.rate == this.rate)return (this.stage - x.stage);
else {
double com= x.rate - this.rate;
if(com>0) return 1;
if(com<0) return -1;
return 0;
}
}
}
class Solution {
public int[] solution(int N, int[] stages) {
int[] answer = new int[N];
ArrayList<Point> arr = new ArrayList<>();
int max = stages.length;
for(int i=1;i<=N;i++){
int cnt=0;
for(int j=0;j<stages.length;j++){
if(i==stages[j])cnt++;
}
arr.add(new Point(i, (float)cnt/max));
max-=cnt;
}
Collections.sort(arr);
for(int i=0;i<N;i++){
answer[i]=arr.get(i).stage;
}
return answer;
}
}