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
相关推荐
千禧皓月2 分钟前
huggingface-cli下载数据集和模型
python
DREAM依旧15 分钟前
本地微调的Ollama模型部署到Dify平台上
人工智能·python
小陈phd16 分钟前
langGraph从入门到精通(九)——基于LangGraph构建具备多工具调用与自动化摘要能力的智能 Agent
人工智能·python·langchain
一晌小贪欢16 分钟前
Python 对象的“Excel 之旅”:使用 openpyxl 高效读写与封装实战
开发语言·python·excel·表格·openpyxl·python办公·读取表格
【赫兹威客】浩哥17 分钟前
【赫兹威客】Python解释器部署教程
python
鹿角片ljp19 分钟前
力扣112. 路径总和:递归DFS vs 迭代BFS
leetcode·深度优先·宽度优先
im_AMBER19 分钟前
Leetcode 104 两两交换链表中的节点
笔记·学习·算法·leetcode
代码or搬砖22 分钟前
Prompt(提示词工程)
人工智能·python·prompt
程序员-King.24 分钟前
day159—动态规划—打家劫舍(LeetCode-198)
c++·算法·leetcode·深度优先·回溯·递归
浅念-27 分钟前
C语言——单链表
c语言·开发语言·数据结构·经验分享·笔记·算法·leetcode