Beats 98% python - easy to understand


  • 1
    Y
    
    class Solution(object):    
        def findRelativeRanks(self, nums):
            """
            :type nums: List[int]
            :rtype: List[str]
            """
            # return the rank index
            # replace rank index with medal
    
            sorted_nums = sorted(nums, reverse=True)
            dic = {}
            medal = {0: 'Gold Medal', 1: 'Silver Medal', 2: 'Bronze Medal'}
            for i, n in enumerate(sorted_nums):
                if i in medal:
                    dic[n] = medal[i]
                else:
                    dic[n] = str(i + 1)
            output = []
            for n in nums:
                output.append(dic[n])
            return output
                
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.