Skip to content

Commit

Permalink
실패율 - level1
Browse files Browse the repository at this point in the history
  • Loading branch information
sey2 authored Aug 15, 2022
1 parent 314217b commit 464464c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions programmers/FailureRate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

class Solution {
public static int[] solution(int N, int[] stages) {
int[] answer = new int[N];

Arrays.sort(stages);

Map<Integer, Double> stageRatio = new HashMap<>();


for(int i=1; i<=N; i++){
int curStageNum = 0;
int noClear = 0;

if(i > stages[stages.length-1] )
stageRatio.put(i, 0.0);
else{
for (int j = 0; j < stages.length; j++) {
if (stages[j] >= i) curStageNum++;

if (stages[j] == i && stages[j] >= i) noClear++;
}
stageRatio.put(i, (double) noClear / (double) curStageNum);
}
}

List<Integer> keySetList = new ArrayList<>(stageRatio.keySet());
Collections.sort(keySetList, (o1, o2) -> (stageRatio.get(o2).compareTo(stageRatio.get(o1))));

int cnt = 0;
for(var a: keySetList)
answer[cnt++] = a;


return answer;
}
}

0 comments on commit 464464c

Please sign in to comment.