Numpy Solution


  • 0
    M
    import numpy as np
    titles={1:"Gold Medal", 2:"Silver Medal", 3:"Bronze Medal"}
    
    class Solution(object):
        def findRelativeRanks(self, nums):
            """
            :type nums: List[int]
            :rtype: List[str]
            """
            inxs,n,cnt=np.argsort(nums),len(nums),0
            for inx in inxs[::-1]:
                nums[inx]=titles.get(cnt+1,str(cnt+1))
                cnt+=1
            return nums
    

Log in to reply
 

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