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
相关推荐
2301_7820404510 小时前
CSS Flex布局中如何实现导航栏与Logo的左右分布_利用justify-content- space-between
jvm·数据库·python
yaoxin52112310 小时前
400. Java 文件操作基础 - 使用 Buffered Stream I/O 读取文本文件
java·开发语言·python
用户83562907805111 小时前
使用 Python 自动创建 Excel 折线图
后端·python
小白学大数据11 小时前
面向大规模爬取:Python 全站链接爬虫优化(过滤 + 断点续爬)
开发语言·爬虫·python
WL_Aurora11 小时前
【每日一题】贪心
python·算法
IT策士12 小时前
Python 中间件系列:redis 深入浅出
redis·python·中间件
Dxy123931021612 小时前
Python Pillow库:`img.format`与`img.mode`的区别详解
开发语言·python·pillow
༒࿈南林࿈༒13 小时前
刺猬猫小说下载
python·js逆向
星星码️13 小时前
LeetCode刷题简单篇之反转字母
c++·算法·leetcode
.柒宇.13 小时前
AI-Agent入门实战-AI私厨
人工智能·python·langchain·agent·fastapi