Simple Python Solution


  • 0
    M
        def findRelativeRanks(self, nums):
            if not nums:
                return []
            
            locs = { nums[i]: i for i in xrange(len(nums)) }
            
            ranks = ['']*len(nums)
            
            nums.sort(reverse=True)
            
            ranks[locs[nums[0]]] = "Gold Medal"
            
            if len(nums) < 2:
                return ranks
            
            ranks[locs[nums[1]]] = "Silver Medal"
            
            if len(nums) < 3:
                return ranks
            
            ranks[locs[nums[2]]] = "Bronze Medal"
            
            curr_rank = 4
            for i in xrange(3, len(nums)):
                ranks[locs[nums[i]]] = str(curr_rank)
                curr_rank += 1
            
            return ranks
    

Log in to reply
 

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