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; } }
leetcode506
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:leetcode167
下一篇:leetcode530
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【LeetCode】39. 组合总和
【LeetCode】39. 组合总和
leetcode 数据结构与算法 C++ -
【LeetCode】705. 设计哈希集合
【LeetCode】705. 设计哈希集合
leetcode 数据结构与算法 C++ -
【LeetCode】706. 设计哈希映射
【LeetCode】706. 设计哈希映射
leetcode 数据结构与算法 C++ -
506. 相对名次、Leetcode的Go实现
博客主页:?看看是李XX还是李歘歘??每天分享一些包括但不限于计算机基础、算法等相关的知识点??点关注不迷路
leetcode golang 算法 数组 i++ -
【LeetCode】第31天 - 506. 相对名次
506. 相对名次题目描述解题思路代码实现题目描述解题思路首先使用一个哈希表,哈希表的key,value分别存放第i位运
java leetcode 算法 hash 赋值 -
LeetCode---506.相对名次(pair的使用)
在这个代码中,有一个问题是在排序时,sort 函数的第三个参数应该是一个比较函数对象,而不是简单地使用 less(),因为 arr 是
leetcode 算法 职场和发展 数组 函数对象 -
Leetcode 506. 相对名次(可以,一次过)
给你一个长度为 n 的整数
i++ 数组 4th -
HaaS506 - HaaS506资源目录
HaaS 506是煜瑛微电子科技有限公
物联网 单片机 嵌入式硬件 haas506 2.0 python -
nyoj 506 洗澡
直接从1-n选择。#include int main(){ int n,sum,i,p,flag; while(scanf("%d"reak;
nyoj506 洗澡 #include i++ -
506,无重叠区间
无重叠区间
编程开发 无重叠区间