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
相关推荐
千寻girling1 小时前
面试官 : “ 说一下 Python 中的常用的 字符串和数组 的 方法有哪些 ? ”
人工智能·后端·python
第一程序员1 小时前
Python基础学习路径:非科班转码者的入门指南
python·github
u0136863821 小时前
将Python Web应用部署到服务器(Docker + Nginx)
jvm·数据库·python
smchaopiao2 小时前
Python中字典与列表合并的问题与解决方法
开发语言·python
卡尔特斯2 小时前
Ultralytics YOLO26 自动对指定标注文件夹区分标注素材脚本与训练脚本
python·openai
2501_921649493 小时前
期货 Tick 级数据与基金净值历史数据 API 接口详解
开发语言·后端·python·websocket·金融·区块链
njidf3 小时前
实战:用Python开发一个简单的区块链
jvm·数据库·python
Rick19933 小时前
慢SQL优化
数据库·python·sql
gc_22993 小时前
学习python使用Ultralytics的YOLO26进行分割的基本用法
python·分割·ultralytics·yolo26
kronos.荒3 小时前
搜索二维矩阵中的target——二分查找或者二叉搜索树(python)
python·矩阵·二分查找