Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".

Example 1:

Input: [5, 4, 3, 2, 1]
Output: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"]
Explanation: The first three athletes got the top three highest scores, so they got "Gold Medal", "Silver Medal" and "Bronze Medal".
For the left two athletes, you just need to output their relative ranks according to their scores.

Note:

  1. N is a positive integer and won't exceed 10,000.
  2. All the scores of athletes are guaranteed to be unique.

Code

class Solution:
def findRelativeRanks(self, nums):
if len(nums) == 1: return ["Gold Medal"]
if len(nums) == 2: return ["Gold Medal", "Silver Medal"] if nums[0] > nums[1] else ["Silver Medal", "Gold Medal"]
ans, d = [0]*len(nums), sorted([(num, index) for index, num in enumerate(nums)], reverse = True)
ans[d[0][1]], ans[d[1][1]], ans[d[2][1]] = "Gold Medal", "Silver Medal", "Bronze Medal"
for i in range(3, len(d)):
ans[d[i][1]] = str(i+1)
return ans

[LeetCode] 506. Relative Ranks_Easy tag: Sort的更多相关文章

  1. [LeetCode] 455. Assign Cookies_Easy tag: Sort

    Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...

  2. [LeetCode] 252. Meeting Rooms_Easy tag: Sort

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  3. LeetCode 506. 相对名次(Relative Ranks) 39

    506. 相对名次 506. Relative Ranks 题目描述 给出 N 名运动员的成绩,找出他们的相对名次并授予前三名对应的奖牌.前三名运动员将会被分别授予"金牌",&qu ...

  4. 【leetcode】506. Relative Ranks

    problem 506. Relative Ranks solution1:使用优先队列: 掌握priority_queue 和 pair的使用: class Solution { public: v ...

  5. [LeetCode] 130. Surrounded Regions_Medium tag: DFS/BFS

    Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'. A reg ...

  6. [LeetCode] 415. Add Strings_Easy tag: String

    Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2 ...

  7. 【LeetCode】506. Relative Ranks 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 argsort 堆 日期 题目地址:https ...

  8. [LeetCode] 581. Shortest Unsorted Continuous Subarray_Easy tag: Sort, Stack

    Given an integer array, you need to find one continuous subarray that if you only sort this subarray ...

  9. [LeetCode&Python] Problem 506. Relative Ranks

    Given scores of N athletes, find their relative ranks and the people with the top three highest scor ...

随机推荐

  1. J - Intersection

    来源poj 1410 You are to write a program that has to decide whether a given line segment intersects a g ...

  2. Mysql 全文搜索 Match Against用法

    全文检索在 MySQL 中就是一个 FULLTEXT 类型索引.FULLTEXT 索引用于 MyISAM 表,可以在 CREATE TABLE 时或之后使用 ALTER TABLE 或 CREATE ...

  3. favicon.ico 网站小图标标识

    随便打开一个网页:比如 http://www.baidu.com/ 可以看到在浏览器的标签头上面显示了一个图标,这个图标是:,也就是我们常说的favicon.ico. 由于这篇文章主要讨论favico ...

  4. C#打印标签

    一个复杂的标签包括一个复杂的表格样式和二维码.条形码等内容.所以如果直接绘制的方式将会非常的麻烦,所以采用使用的方案是使用模板的方式:1.使用Excel创建出想要的模板的样式.2.对模板中的动态内容进 ...

  5. .NET Core开发日志——HttpClientFactory

    当需要向某特定URL地址发送HTTP请求并得到相应响应时,通常会用到HttpClient类.该类包含了众多有用的方法,可以满足绝大多数的需求.但是如果对其使用不当时,可能会出现意想不到的事情. 博客园 ...

  6. 老师的blog整理 .网络编程部分 .网络编程部分 前端部分 django基础部分

    老师的blog整理 python基础部分: 宝哥blog: https://www.cnblogs.com/guobaoyuan/ 开哥blog: https://home.cnblogs.com/u ...

  7. *** FATAL ERROR L250: CODE SIZE LIMIT IN RESTRICTED VERSION EXCEEDED

    *** FATAL ERROR L250: CODE SIZE LIMIT IN RESTRICTED VERSION EXCEEDED 在软件已经执行破解仍然出现,是因为工程是破解前建立的,要先执行 ...

  8. [No0000173]97 条 Linux 常用命令总结

    1.ls [选项] [目录名 | 列出相关目录下的所有目录和文件 -a  列出包括.a开头的隐藏文件的所有文件-A  通-a,但不列出"."和".."-l  列 ...

  9. [No0000149]ReSharper操作指南6/16-编码协助之其他协助

    语法高亮 ReSharper扩展了默认Visual Studio的符号高亮显示.此外,它还会使用可配置的颜色突出显示字段,局部变量,类型和其他标识符.例如,ReSharper语法突出显示允许您轻松区分 ...

  10. 【每日一题】 UVA - 1589 Xiangqi 函数+模拟 wa了两天

    题意:背景就是象棋, 题解:坑点1(wa的第一天):将军可以吃掉相邻的棋子,(然行列也写反了orz) 坑点2(wa的第二天):将军到马要反过来写,边界有误,并且第一次碰到的车才算(写到后来都忘了) # ...