-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathfindRelativeRanks.java
30 lines (24 loc) · 972 Bytes
/
findRelativeRanks.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
class Solution {
public String[] findRelativeRanks(int[] nums) {
String [] result = new String[nums.length];
if(nums.length == 0) return result;
int [] temp = new int[nums.length];
HashMap<Integer, String> map = new HashMap<>();
System.arraycopy(nums, 0, temp, 0, nums.length);
Arrays.sort(temp);
for(int i=0; i<temp.length; i++)
{
if(i < temp.length-3)
map.put(temp[i], String.valueOf(temp.length - i));
else if(i == temp.length -1)
map.put(temp[i], "Gold Medal");
else if(i == temp.length-2)
map.put(temp[i], "Silver Medal");
else if(i == temp.length-3)
map.put(temp[i], "Bronze Medal");
}
for(int i=0; i<nums.length; i++)
result[i] = map.get(nums[i]);
return result;
}
}