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. H - The Frog's Games

    The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. On ...

  2. shell 脚本部分变量含义

    $ # 传递到脚本的参数个数$ * 以一个单字符串显示所有向脚本传递的参数.与位置变量不同,此选项参数可超过9个$ $ 脚本运行的当前进程I D号$ ! 后台运行的最后一个进程的进程I D号$ @ 与 ...

  3. limits.conf文件修改注意事项

    limits.conf文件限制着用户可以使用的最大文件数,最大线程,最大内存等资源使用量. vim /etc/security/limits.conf * soft nofile * hard nof ...

  4. Tif文件合并类

    using System; using System.Collections; using System.Collections.Generic; using System.Drawing; usin ...

  5. ASP.NET MVC + EF 更新的几种方式

    1.常用 db.Entry(实体).State = EntityState.Modified;db.SaveChanges(); 2.指定更新 db.Configuration.ValidateOnS ...

  6. PAT甲级1052 Linked List Sorting

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805425780670464 题意: 给定一些内存中的节点的地址,值 ...

  7. ASP.NET 前端Ajax获取数据并刷新

    控制器中↓ /// <summary> /// 根据ID来进行展示数据 /// </summary> /// <param name="instru_id&qu ...

  8. 分布式文件系统HDFS,大数据存储实战(一)

    本文进行了以下工作: OS中建立了两个文件,文件中保存了几组单词. 把这两个文件导入了hadoop自己的文件系统. 介绍删除已导入hadoop的文件和目录的方法,以便万一发生错误时使用. 使用列表命令 ...

  9. https://pypi.org/project/py-mysql2pgsql/

    https://packages.ubuntu.com/trusty/postgresql-server-dev-9.3 所以使用下面的命令即可安装python-dev: yum install py ...

  10. 牛客网Wannafly挑战赛25A 因子 数论

    正解:小学数学数论 解题报告: 传送门 大概会连着写几道相对而言比较简单的数学题,,,之后就会比较难了QAQ 所以这题相对而言还是比较水的,,, 首先这种题目不难想到分解质因数趴,, 于是就先对p和n ...