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://leetcode.com/problems/relative-ranks/#/description

posted on 2017-04-19 11:07  Sempron2800+  阅读(142)  评论(0编辑  收藏  举报