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]
相关推荐
alvin_200521 小时前
python之OpenGL应用(二)Hello Triangle
python·opengl
铁蛋AI编程实战21 小时前
通义千问 3.5 Turbo GGUF 量化版本地部署教程:4G 显存即可运行,数据永不泄露
java·人工智能·python
jiang_changsheng1 天前
RTX 2080 Ti魔改22GB显卡的最优解ComfyUI教程
python·comfyui
0思必得01 天前
[Web自动化] Selenium处理滚动条
前端·爬虫·python·selenium·自动化
Charlie_lll1 天前
力扣解题-移动零
后端·算法·leetcode
沈浩(种子思维作者)1 天前
系统要活起来就必须开放包容去中心化
人工智能·python·flask·量子计算
2301_790300961 天前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
m0_736919101 天前
用Pandas处理时间序列数据(Time Series)
jvm·数据库·python
getapi1 天前
实时音视频传输与屏幕共享(投屏)
python
iAkuya1 天前
(leetcode)力扣100 62N皇后问题 (普通回溯(使用set存储),位运算回溯)
算法·leetcode·职场和发展