506. Relative Ranks
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 73% Topics: Array, Sorting, Heap (Priority Queue)
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(nlogn)
# Space: O(n)
class Solution(object):
def findRelativeRanks(self, nums):
"""
:type nums: List[int]
:rtype: List[str]
"""
sorted_nums = sorted(nums)[::-1]
ranks = ["Gold Medal", "Silver Medal", "Bronze Medal"] + map(str, range(4, len(nums) + 1))
return map(dict(zip(sorted_nums, ranks)).get, nums)
Solution from kamyu104/LeetCode-Solutions · MIT