Skip to content

Commit 82790b0

Browse files
committed
Relative Ranks
1 parent ca61cb5 commit 82790b0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package leetcode2018;
2+
3+
import java.util.Collections;
4+
import java.util.PriorityQueue;
5+
6+
public class RelativeRanks {
7+
8+
public String[] findRelativeRanks(int[] nums) {
9+
PriorityQueue<Integer> q = new PriorityQueue<>(10, Collections.reverseOrder());
10+
for(int i : nums){
11+
q.offer(i);
12+
}
13+
14+
int i=0;
15+
String[] s = new String[nums.length];
16+
Integer val=null;
17+
while( (val = q.poll()) != null) {
18+
if(i==0)
19+
s[i]="Gold Medal";
20+
if(i==1)
21+
s[i]="Silver Medal";
22+
if(i==2)
23+
s[i]="Bronze Medal";
24+
else
25+
s[i]=val+"";
26+
i++;
27+
28+
}
29+
return s;
30+
}
31+
}

0 commit comments

Comments
 (0)