C# solution


  • 0
    public class Solution {
            public string[] FindRelativeRanks(int[] nums)
            {
                int[] copy = new int[nums.Length];
                nums.CopyTo(copy, 0);
                string[] results = new string[nums.Length];
                Array.Sort(copy);
    
                int count = 1;
                for (int i = copy.Length - 1; i >= 0; i--)
                {
                    if (count == 1)
                    {
                        results[GetIndex(nums, copy[i])] = "Gold Medal";
                    }
                    else if (count == 2)
                    {
                        results[GetIndex(nums, copy[i])] = "Silver Medal";
                    }
                    else if (count == 3)
                    {
                        results[GetIndex(nums, copy[i])] = "Bronze Medal";
                    }
                    else
                    {
                        results[GetIndex(nums, copy[i])] = (nums.Length - i).ToString();
                    }
                    count += 1;
                }
    
                return results;
    
    
            }
    
            public int GetIndex(int[] nums, int n)
            {
                for (int i = 0; i < nums.Length; i++)
                {
                    if (nums[i] == n)
                    {
                        return i;
                    }
                }
    
                return -1;
            }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.