Skip to content

Latest commit

 

History

History
24 lines (22 loc) · 674 Bytes

506.md

File metadata and controls

24 lines (22 loc) · 674 Bytes

506. Relative Ranks

Solution 1 (time O(nlog(n)), space O(n))

class Solution(object):
    def findRelativeRanks(self, score):
        """
        :type score: List[int]
        :rtype: List[str]
        """
        rank = sorted(enumerate(score), key=lambda x: -x[1])
        ans = ["" for _ in range(len(score))]
        for i, (idx, _) in enumerate(rank):
            if i == 0:
                ans[idx] = "Gold Medal"
            elif i == 1:
                ans[idx] = "Silver Medal"
            elif i == 2:
                ans[idx] = "Bronze Medal"
            else:
                ans[idx] = str(i + 1)
        return ans