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
相关推荐
dev派1 小时前
AI Agent 系统中的常用 Workflow 模式(2) Evaluator-Optimizer模式
python·langchain
前端付豪3 小时前
AI 数学辅导老师项目构想和初始化
前端·后端·python
用户0332126663673 小时前
将 PDF 文档转换为图片【Python 教程】
python
xlp666hub4 小时前
Leetcode第五题:用C++解决盛最多水的容器问题
linux·c++·leetcode
悟空爬虫5 小时前
UV实战教程,我啥要从Anaconda切换到uv来管理包?
python
dev派5 小时前
AI Agent 系统中的常用 Workflow 模式(1)
python·langchain
明月_清风7 小时前
从“能用”到“专业”:构建生产级装饰器与三层逻辑拆解
后端·python
曲幽16 小时前
数据库实战:FastAPI + SQLAlchemy 2.0 + Alembic 从零搭建,踩坑实录
python·fastapi·web·sqlalchemy·db·asyncio·alembic
用户83562907805121 小时前
Python 实现 PowerPoint 形状动画设置
后端·python
ponponon1 天前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python