public class Solution { public string[] FindRelativeRanks(int[] nums) { var list = nums.OrderByDescending(x => x).ToList(); var count = nums.Count(); Dictionary<int, string> dic = new Dictionary<int, string>(); string[] ary = new string[count]; for (int i = 0; i < count; i++) { if (i == 0) { dic.Add(list[i], "Gold Medal"); } else if (i == 1) { dic.Add(list[i], "Silver Medal"); } else if (i == 2) { dic.Add(list[i], "Bronze Medal"); } else { dic.Add(list[i], (i + 1).ToString()); } } for (int i = 0; i < count; i++) { ary[i] = dic[nums[i]]; } return ary; } }
转载于:https://www.cnblogs.com/asenyang/p/6732336.html