forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.java
More file actions
62 lines (51 loc) ยท 1.62 KB
/
3.java
File metadata and controls
62 lines (51 loc) ยท 1.62 KB
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
import java.util.*;
class Node implements Comparable<Node> {
private int stage;
private double fail;
public Node(int stage, double fail) {
this.stage = stage;
this.fail = fail;
}
public int getStage() {
return this.stage;
}
@Override
public int compareTo(Node other) {
if (this.fail == other.fail) {
return Integer.compare(this.stage, other.stage);
}
return Double.compare(other.fail, this.fail);
}
}
class Solution {
public int[] solution(int N, int[] stages) {
int[] answer = new int[N];
ArrayList<Node> arrayList = new ArrayList<>();
int length = stages.length;
// ์คํ
์ด์ง ๋ฒํธ๋ฅผ 1๋ถํฐ N๊น์ง ์ฆ๊ฐ์ํค๋ฉฐ
for (int i = 1; i <= N; i++) {
// ํด๋น ์คํ
์ด์ง์ ๋จธ๋ฌผ๋ฌ ์๋ ์ฌ๋์ ์ ๊ณ์ฐ
int cnt = 0;
for (int j = 0; j < stages.length; j++) {
if (stages[j] == i) {
cnt += 1;
}
}
// ์คํจ์จ ๊ณ์ฐ
double fail = 0;
if (length >= 1) {
fail = (double) cnt / length;
}
// ๋ฆฌ์คํธ์ (์คํ
์ด์ง ๋ฒํธ, ์คํจ์จ) ์์ ์ฝ์
arrayList.add(new Node(i, fail));
length -= cnt;
}
// ์คํจ์จ์ ๊ธฐ์ค์ผ๋ก ๊ฐ ์คํ
์ด์ง๋ฅผ ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ
Collections.sort(arrayList);
// ์ ๋ ฌ๋ ์คํ
์ด์ง ๋ฒํธ ๋ฐํ
for (int i = 0; i < N; i++) {
answer[i] = arrayList.get(i).getStage();
}
return answer;
}
}