Python | Leetcode Python题解之第506题相对名次

题目:

题解:

python 复制代码
class Solution:
    desc = ("Gold Medal", "Silver Medal", "Bronze Medal")

    def findRelativeRanks(self, score: List[int]) -> List[str]:
        ans = [""] * len(score)
        arr = sorted(enumerate(score), key=lambda x: -x[1])
        for i, (idx, _) in enumerate(arr):
            ans[idx] = self.desc[i] if i < 3 else str(i + 1)
        return ans
相关推荐
半tour费35 分钟前
TextCNN-NPU移植与性能优化实战
python·深度学习·分类·cnn·华为云
普通网友40 分钟前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python
百锦再1 小时前
第17章 模式与匹配
开发语言·后端·python·rust·django·内存·抽象
普通网友1 小时前
Python函数定义与调用:编写可重用代码的基石
jvm·数据库·python
倦王1 小时前
力扣日刷251117
算法·leetcode·职场和发展
普通网友1 小时前
使用Python进行PDF文件的处理与操作
jvm·数据库·python
MZ_ZXD0012 小时前
springboot流浪动物救助平台-计算机毕业设计源码08780
java·spring boot·后端·python·spring·flask·课程设计
十步杀一人_千里不留行2 小时前
解释器模式:为 LLM 构建迷你 DSL 解释器,实现 Prompt 编排语言
python·prompt·解释器模式
这儿有一堆花2 小时前
python视觉开发
开发语言·python
普通网友2 小时前
编写一个Python脚本自动下载壁纸
jvm·数据库·python