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
相关推荐
齐齐大魔王1 分钟前
python爬虫学习进程(四)
爬虫·python·学习
永远都不秃头的程序员(互关)3 分钟前
昇腾CANN算子开发实践:从入门到性能优化
人工智能·python·机器学习
AI Echoes8 分钟前
LangGraph 需求转换图架构的技巧-CRAG实现
人工智能·python·langchain·prompt·agent
AI Echoes8 分钟前
LangChain LLM函数调用使用技巧与应用场景
人工智能·python·langchain·prompt·agent
IT·小灰灰17 分钟前
腾讯HY2.0 Think推理模型深度解析:技术突破、应用场景与实践指南
开发语言·人工智能·python·深度学习·神经网络·算法·数据分析
m0_7048878930 分钟前
Day 27
人工智能·python·机器学习
小南家的青蛙33 分钟前
LeetCode第773题 - 滑动谜题
算法·leetcode·职场和发展
毕设源码-钟学长1 小时前
【开题答辩全过程】以 基于Python爬虫的二手房信息爬取及分析为例,包含答辩的问题和答案
开发语言·爬虫·python
Swizard1 小时前
告别 NDK 噩梦!用 Python + Chaquopy 在 Android 上 5 分钟跑通 Paddle AI 模型
python·ai·移动开发
深蓝海拓1 小时前
用于优化和改进YOLO11的一些方法
人工智能·python·yolo·机器学习