강의로 돌아가기

### 테스트 1,6,7,9,13,23,24,25 실패

뭐가 문제 일까요???
(또 자바는 Linq 어떻게 써요???)

###### 작성중인 코드―Solution.java
``````1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

class Solution {
public int[] solution(int N, int[] stages) {
if(stages == null ) return null;
if(stages.length <= 0) return null;

int[] userPerStage = new int[N + 1];
Map<Integer, Double> failRatePerStages = new HashMap<Integer, Double>();

for(int i=0; i<stages.length; i++) {
userPerStage[stages[i] - 1] += 1;
}

int attendUserCount = stages.length;
for(int i=0; i<userPerStage.length; i++) {
int stage = (i+1);
Double notPassRate = userPerStage[i] / (attendUserCount + 0.0);
if(N > i) {
failRatePerStages.put(stage, notPassRate);
}
attendUserCount -= userPerStage[i];
}

Map<Integer, Double> sorted = sortByComparator(failRatePerStages, false);
Object[] keys = sorted.keySet().toArray();
int[] results = new int[keys.length];
for(int i=0; i<results.length; i++) {
results[i] = (int)keys[i];
}

return results;
}

private Map<Integer, Double> sortByComparator(Map<Integer, Double> unsortMap, final boolean order)
{
List<Entry<Integer, Double>> list = new LinkedList<Entry<Integer, Double>>(unsortMap.entrySet());

// Sorting the list based on values
Collections.sort(list, new Comparator<Entry<Integer, Double>>()
{
public int compare(Entry<Integer, Double> o1,
Entry<Integer, Double> o2)
{
if (order)
{
return o1.getValue().compareTo(o2.getValue());
}
else
{
return o2.getValue().compareTo(o1.getValue());

}
}
});

// Maintaining insertion order with the help of LinkedList
Map<Integer, Double> sortedMap = new LinkedHashMap<Integer, Double>();
for (Entry<Integer, Double> entry : list)
{
sortedMap.put(entry.getKey(), entry.getValue());
}

return sortedMap;
}
}
``````
##### 1 개의 답변

스테이지에 도달한 경우가 없을 경우에 실패율을 0으로 처리하라는 조건을 안하신 것 같네요.