-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode_2.java
More file actions
52 lines (48 loc) · 1.22 KB
/
leetcode_2.java
File metadata and controls
52 lines (48 loc) · 1.22 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
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.ArrayList;
public class leetcode_2 {
public static void minheap(int [] arr) {
int [] newArray = new int[arr.length];
String [] ranking = new String[arr.length];
String [] finalRanking = new String[arr.length];
PriorityQueue<Integer> heap = new PriorityQueue<Integer>(Collections.reverseOrder());
for(int i=0; i<arr.length; i++) {
heap.add(arr[i]);
}
for(int i=0; i<arr.length; i++) {
// System.out.println(heap.peek()+" ");
newArray[i]=heap.peek();
heap.poll();
}
for(int i=0; i<newArray.length; i++) {
if(i==0) {
ranking[i]="Gold Medal";
}
else if (i==1) {
ranking[i]="Silver Medal";
}
else if (i==2) {
ranking[i]="Bronze Medal";
}
else {
int r = i+1;
ranking[i]=Integer.toString(r);
}
}
for(int i =0; i<arr.length; i++) {
for(int j=0; j<newArray.length; j++) {
if(arr[i]==newArray[j]) {
finalRanking[i]=ranking[j];
break;
}
}
}
System.out.println(finalRanking[1]);
}
public static void main(String[] args) {
int [] arr = {10,3,8,9,4};
leetcode_2.minheap(arr);
}
}