-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy path0506-RelativeRanks.cs
38 lines (33 loc) · 1.14 KB
/
0506-RelativeRanks.cs
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
//-----------------------------------------------------------------------------
// Runtime: 260ms
// Memory Usage: 34.9 MB
// Link: https://leetcode.com/submissions/detail/344770619/
//-----------------------------------------------------------------------------
using System.Linq;
namespace LeetCode
{
public class _0506_RelativeRanks
{
public string[] FindRelativeRanks(int[] nums)
{
var max = nums.Max();
var index = new int[max + 1];
for (int i = 0; i < nums.Length; i++)
index[nums[i]] = i + 1;
var result = new string[nums.Length];
var rank = 1;
for (int i = max; i >= 0; i--)
{
if (index[i] != 0)
{
if (rank == 1) result[index[i] - 1] = "Gold Medal";
else if (rank == 2) result[index[i] - 1] = "Silver Medal";
else if (rank == 3) result[index[i] - 1] = "Bronze Medal";
else result[index[i] - 1] = rank.ToString();
rank++;
}
}
return result;
}
}
}