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. windous----常用命令集合

    Windous常用命令 winver---------检查Windows版本 wmimgmt.msc----打开windows管理体系结构(WMI) wupdmgr--------windows更新程 ...

  2. 网龙“MAD技术论坛”在榕举办 200余位技术人才共话“改变教育”

    9月16日,由网龙网络公司主办.msup协办的“MAD技术论坛”在榕举办,来自美国.香港.苏州等地的技术大牛受邀来到福州,围绕“Make a difference to education”这一论坛主 ...

  3. 使用ASP.NET Core的User Secrets特性

    昨天在一个集成测试项目中实际使用 ASP.NET Core 的 user secrets 保存敏感配置信息,避免了直接保存在 appsettings.json 中,在这篇随笔中记录一下. 使用 use ...

  4. {MySQL存储引擎介绍}一 存储引擎解释 二 MySQL存储引擎分类 三 不同存储引擎的使用

    MySQL存储引擎介绍 MySQL之存储引擎 本节目录 一 存储引擎解释 二 MySQL存储引擎分类 三 不同存储引擎的使用 一 存储引擎解释 首先确定一点,存储引擎的概念是MySQL里面才有的,不是 ...

  5. ubuntu汉化

    寻找 Simplified Chinese,点击下面的apply 回到这里在最下面找到刚刚安装的语言,是灰色的,左键点击,将它拖到最上面,点击应用到整个系统,配置完成.重启系统就变成中文了. 晚上不要 ...

  6. mysql root看不到mysql表

    1.首先停止mysql服务:service mysqld stop2.加参数启动mysql:/usr/bin/mysqld_safe --skip-grant-tables & 然后就可以无任 ...

  7. c++中new的三种用法详细解析

    转载至: http://www.jb51.net/article/41524.htm 以下的是对c++中new的三种使用方法进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助. 一. ...

  8. 在dbgrideh中允许选择多行,如何知道哪些行被选中

    是个BOOKMARK类型的属性. SelectedRows: TBookmarkList procedure TForm1.Button1Click(Sender: TObject); var i, ...

  9. MonkeyRunner_手机触摸屏幕坐标获取

    坐标单位为像素,获取方式包括手机自带.画图软件和photoshop软件. 方式一.android4.0以上系统手机自带坐标功能,在设置->开发者选项->显示指针位置 方式二.画图或phot ...

  10. Linux中常用命令

    .cd命令 cd    回到跟目录 cd uqihong     进入到uqihong这个文件夹(且cd命令只能一级一级的进入) 2.复制命令      cp -r /usr/local/tomcat ...