-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHEAP_506
More file actions
35 lines (35 loc) · 1002 Bytes
/
Copy pathHEAP_506
File metadata and controls
35 lines (35 loc) · 1002 Bytes
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
class Solution {
class Pair{
int score;
int index;
Pair(int score, int index){
this.score = score;
this.index = index;
}
}
public String[] findRelativeRanks(int[] score) {
PriorityQueue<Pair> maxHeap =new PriorityQueue<>((a,b) -> b.score - a.score);
for(int i=0; i<score.length; i++){
maxHeap.offer(new Pair(score[i], i));
}
String[] ans = new String[score.length];
int rank = 1;
while(!maxHeap.isEmpty()){
Pair curr = maxHeap.poll();
if(rank == 1){
ans[curr.index] = "Gold Medal";
}
else if(rank == 2){
ans[curr.index] = "Silver Medal";
}
else if(rank == 3){
ans[curr.index] = "Bronze Medal";
}
else{
ans[curr.index] = String.valueOf(rank);
}
rank++;
}
return ans;
}
}