반응형
문제
https://leetcode.com/problems/relative-ranks/
해설
정렬을 활용하는 문제였다.
import copy
class Solution:
def findRelativeRanks(self, score: List[int]) -> List[str]:
prize = {
0: "Gold Medal",
1: "Silver Medal",
2: "Bronze Medal",
}
sorted_score = copy.deepcopy(score)
sorted_score.sort(reverse=True)
result = []
for r in [sorted_score.index(s) for s in score]:
if r in prize.keys():
result.append(prize[r])
else:
result.append(str(r+1))
return result
반응형