Python | Leetcode Python题解之第332题重新安排行程

题目:

题解:

python 复制代码
class Solution:
    def findItinerary(self, tickets: List[List[str]]) -> List[str]:
        def dfs(curr: str):
            while vec[curr]:
                tmp = heapq.heappop(vec[curr])
                dfs(tmp)
            stack.append(curr)

        vec = collections.defaultdict(list)
        for depart, arrive in tickets:
            vec[depart].append(arrive)
        for key in vec:
            heapq.heapify(vec[key])
        
        stack = list()
        dfs("JFK")
        return stack[::-1]
相关推荐
hongyucai11 分钟前
详解rlinf强化学习四步曲
人工智能·python·算法·架构
c_lb728811 分钟前
2026年下半年AI量化工具,阶段不同重点也不同
人工智能·python
Xpower 1729 分钟前
详细解释 Codex 最近一次功能更新,以及 GPT-5.6 Sol、Terra、Luna 的能力、价格、使用方式和适用场景。
人工智能·python·gpt·学习
许彰午1 小时前
87_Python Django模型与数据库
数据库·python·django
程序员小远1 小时前
性能测试之性能调优
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·性能测试
凌波粒1 小时前
LeetCode--53. 最大子序和(贪心算法)
算法·leetcode·贪心算法
金銀銅鐵1 小时前
[Python] 借助图形化界面探索模n运算的规律
python·数学
Hesionberger1 小时前
快速求解完全平方数的最少数量
开发语言·数据结构·python·算法·leetcode·c#
aqiu1111111 小时前
【算法日记 19】LeetCode 1. 两数之和:梦开始的地方,哈希表的降维打击
算法·leetcode·职场和发展
xywww1685 小时前
大模型 API 选型实战:GPT、Gemini、Claude 接入时该看哪些指标?
运维·服务器·人工智能·python·gpt·langchain