• leetcode506


    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

  • 相关阅读:
    UVA
    UVA
    UVA
    UVA
    NLP介绍
    新建Springboot项目
    添加ssh密钥
    git 错误合集
    Git入门操作
    Hadoop MapReduce
  • 原文地址:https://www.cnblogs.com/asenyang/p/6732336.html
Copyright © 2020-2023  润新知