deffindRelativeRanks(self, score):"""
:type score: List[int]
:rtype: List[str]
"""# 输入校验ifnot score orany(notisinstance(x,(int,float))for x in score):raise ValueError("Input must be a non-empty list of numbers")# 使用排序代替多次查找最大值
sorted_indices =sorted(range(len(score)), key=lambda i: score[i], reverse=True)# 奖牌名称映射
medal_map ={0:"Gold Medal",1:"Silver Medal",2:"Bronze Medal"}# 初始化结果列表
res =[""]*len(score)# 根据排名填充结果for rank, index inenumerate(sorted_indices):
res[index]= medal_map.get(rank,str(rank +1))return res