a heap-sort solution


  • 0

    here's my heap-sort solution:

    from heapq import heappush, heappop
    class Solution(object):
        def findRelativeRanks(self, a):
            z = []
            for i in range(len(a)): heappush(z, (-a[i], i))
            c = 1
            while z:
                if c > 3: a[heappop(z)[1]] = str(c)
                elif c == 3: a[heappop(z)[1]] = "Bronze Medal"
                elif c == 2: a[heappop(z)[1]] = "Silver Medal"
                elif c == 1: a[heappop(z)[1]] = "Gold Medal"
                c += 1
            return a
    
    

Log in to reply
 

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