Easy C# solution. Sorting and Linq.


  • 1
    T
     public string[] FindRelativeRanks(int[] nums)
     {
         var scores = nums.OrderByDescending(x=>x).ToList();
         return nums.Select(x =>
             {
                 if (x == scores[0])
                     return "Gold Medal";
                 if (x == scores[1])
                     return "Silver Medal";
                 if (x == scores[2])
                     return "Bronze Medal";
                  return (scores.IndexOf(x) + 1).ToString();
             }).ToArray();
     }
    

Log in to reply
 

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