0506. 相对名次 #41
utterances-bot
started this conversation in
Comments
Replies: 0 comments 1 reply
-
从网上抄的别人答案思路,用Hsah表,速度会稍快class Solution:
def findRelativeRanks(self, score: List[int]) -> List[str]:
prize = ["Gold Medal","Silver Medal","Bronze Medal"]
retdict = {}
#直接获得按分数得顺序排名,sorted快速排序
rank = sorted(score,reverse=True)
# #把分数,奖励对应存在字典retdict里
for i in range(len(score)):
if i < 3 :
retdict[rank[i]] = prize[i]
else:
retdict[rank[i]] = str(i+1)
return[retdict[i] for i in score] |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
0506. 相对名次 | 算法通关手册
https://algo.itcharge.cn/Solutions/0500-0599/relative-ranks/
Beta Was this translation helpful? Give feedback.
All reactions