LeetCode 506 相對名次
class solution:
def findRelativeRanks(self, nums):
sorted_nums = sorted(nums)
rank = ['Gold Medal', 'Silver Medal', 'Bronze Medal']+[str(i) for i in range(4, len(nums)+1)]
return map(dict(zip(sorted_nums, rank)).get, nums)
zip 一一打包, dict建立字典,map將函式對指定序列做一一對映
相關推薦
LeetCode 506. 相對名次(C++、python)
給出 N 名運動員的成績,找出他們的相對名次並授予前三名對應的獎牌。前三名運動員將會被分別授予 “金牌”,“銀牌” 和“ 銅牌”("Gold Medal", "Silver Medal", "Bronze Medal")。 (注:分數越高的選手,排名越靠前。) 示例 1:
LeetCode 506 相對名次
class solution: def findRelativeRanks(self, nums): sorted_nums = sorted(nums) rank = ['Gold Medal', 'Silver Medal', 'B
【LeetCode】506. 相對名次
1.題目 給出 N 名運動員的成績,找出他們的相對名次並授予前三名對應的獎牌。前三名運動員將會被分別授予 “金牌”,“銀牌” 和“ 銅牌”(“Gold Medal”, “Silver Medal”,
Leetcode刷題筆記python---相對名次
相對名次 題目 給出 N 名運動員的成績,找出他們的相對名次並授予前三名對應的獎牌。前三名運動員將會被分別授予 “金牌”,“銀牌” 和“ 銅牌”(“Gold Medal”, “Silver Medal”, “Bronze Medal”)。 (注:分數越高的選手,排名越靠前。)
leetcode-506-Relative Ranks
部分 過程 sco let desc 排列 IT find == 題目描述: Given scores of N athletes, find their relative ranks and the people with the top three highest s
LeetCode506-相對名次
就是一個數組裡面,有很多個不重複的數字(成績),將他們的成績對映為他們的排名。 第一名就金牌,後面的4、5、6名這些就輸出相對的排名就好了。 有個問題,數字不是連續的。 其實一開始也沒想到什麼好的方法 怎樣才能做到,知道每個數字的名次,又不搞亂順序呢?因為結果是要返回一個和成績對應名次的陣列。 1、
Leetcode506.Relative Ranks相對名次
給出 N 名運動員的成績,找出他們的相對名次並授予前三名對應的獎牌。前三名運動員將會被分別授予 “金牌”,“銀牌” 和“ 銅牌”("Gold Medal", "Silver Medal", "Bronze Medal")。 (注:分數越高的選手,排名越靠前。) 示例
[LeetCode&Python] Problem 506. Relative Ranks
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",
【LeetCode】506. Relative Ranks【E】【50】
Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gol
[LeetCode]160.Intersection of Two Linked Lists
col style return tro nod sts diff original you Intersection of Two Linked Lists Write a program to find the node at which the intersectio
[LeetCode] Reshape the Matrix 矩陣重塑
ren ati num 我們 資料 call posit tar led In MATLAB, there is a very useful function called ‘reshape‘, which can reshape a matrix into a ne
leetcode題解 || Roman to Integer問題
leet only top xiv har convert 擁有 pro think problem: Given a roman numeral, convert it to an integer. Input is guaranteed to be within
100. Same Tree(LeetCode)
write end nodes ons code logs 相等 same tree treenode Given two binary trees, write a function to check if they are equal or not. Two binar
LeetCode Length of Last Word
archive n-1 art fine ive lan ets hello style 1. 題目Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘
leetcode 209. Minimum Size Subarray Sum
urn https scrip subarray () ins -s mar color https://leetcode.com/problems/minimum-size-subarray-sum/#/description 題目很簡單。題意就是求字符串中長度最小的一
[LeetCode][Java] Subsets
sort arrays ++ lee 題意 integer sel duplicate ati 題目: Given a set of distinct integers, nums, return all possible subsets. Note: Ele
Leetcode:search_insert_position
size search ++ ins urn leet 位置 art -s 一、 題目 給定一個數組和要插入數的大小。求插入的位置。 二、 分析 太水,直接掃描。過……. class Solution { public: int search
(LeetCode)兩個鏈表的第一個公共節點
struct link note lee mono lengthb borde san length LeetCode上面的題目例如以下: Write a program to find the node at which the intersection of t
【LeetCode】091. Decode Ways
rom size etc oss following nbsp pan ron ann 題目: A message containing letters from A-Z is being encoded to numbers using the following map
[LeetCode] Word Abbreviation 單詞縮寫
any array number example note long win min which Given an array of n distinct non-empty strings, you need to generate minimal possible