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
相关推荐
陈辛chenxin11 分钟前
【接口测试】Postman教程
python·selenium·测试工具·postman·可用性测试
程序员小远16 分钟前
Postman详解
自动化测试·软件测试·python·测试工具·测试用例·接口测试·postman
钮钴禄·爱因斯晨43 分钟前
Python常见的文件操作
android·数据库·python
AI小云1 小时前
【数据操作与可视化】Pandas数据处理-Series数据结构
开发语言·数据结构·python·numpy·pandas
Python大数据分析@1 小时前
如何理解Python中的yield用法?
python
Miraitowa_cheems2 小时前
LeetCode算法日记 - Day 108: 01背包
数据结构·算法·leetcode·深度优先·动态规划
源码之家2 小时前
基于python新闻数据分析可视化系统 Hadoop 新闻平台 爬虫 情感分析 舆情分析 可视化 Django框架 vue框架 机器学习 大数据毕业设计✅
大数据·爬虫·python·数据分析·毕业设计·情感分析·新闻
IT油腻大叔2 小时前
DeepSeek-多层注意力计算机制理解
python·深度学习·机器学习
小呀小萝卜儿2 小时前
2025-11-17 学习记录--Python-机器学习作业:项目1 - PM2.5预测
python·学习·机器学习
闲人编程2 小时前
CPython与PyPy性能对比:不同解释器的优劣分析
python·算法·编译器·jit·cpython·codecapsule