-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
34 lines (29 loc) · 1005 Bytes
/
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
class Solution {
public String[] findRelativeRanks(int[] nums) {
int maxScore = 0;
String[] res = new String[nums.length];
for (int num : nums) {
maxScore = Math.max(maxScore, num);
}
Integer[] scoreMap = new Integer[maxScore + 1];
for (int i = 0; i < nums.length; i++) {
scoreMap[nums[i]] = i;
}
int count = 1;
for (int i = scoreMap.length - 1; i >= 0; i--) {
if (scoreMap[i] != null) {
if (count == 1) {
res[scoreMap[i]] = "Gold Medal";
} else if (count == 2) {
res[scoreMap[i]] = "Silver Medal";
} else if (count == 3) {
res[scoreMap[i]] = "Bronze Medal";
} else {
res[scoreMap[i]] = String.valueOf(count);
}
count++;
}
}
return res;
}
}