1. 程式人生 > >LeetCode 506 相對名次

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將函式對指定序列做一一對映