Python-Keeping rank with dictionary


  • 0
    K

    '''
    class Solution(object):
    def findRelativeRanks(self, nums):
    """
    :type nums: List[int]
    :rtype: List[str]
    """
    a=[]
    rank=4
    dix={}
    numss=sorted(nums)[::-1]
    for i in range(len(numss)):
    dix[numss[i]]=i
    for k,v in dix.items():
    if v == 0:
    gold=k
    continue
    if v == 1:
    silver=k
    continue
    if v == 2:
    bronze=k
    continue
    for i in nums:
    if i == gold:
    a.append("Gold Medal")
    continue
    if i == silver:
    a.append("Silver Medal")
    continue
    if i == bronze:
    a.append("Bronze Medal")
    continue
    a.append(str(dix[i]+1))
    return a
    '''


Log in to reply
 

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