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]
相关推荐
2601_9620781943 分钟前
Appium+Python+pytest自动化测试框架详解
自动化测试·python·appium·pytest·移动应用
卷无止境4 小时前
智能体开发环境ADE浅析,编程工具的下一次范式跃迁
后端·python
2601_962300818 小时前
机器学习贴士:使用Python编写MapReduce
hadoop·python·机器学习·mapreduce·数据处理
xyz_CDragon8 小时前
GitHub上4个爆款AI开源Skill:拍照后不用P图,用Codex一键生成高级海报(附效果图+使用教程)
人工智能·python·github·codex·skill
weixin199701080169 小时前
[特殊字符]《跨境二手ERP对接Back Market:标准化API + 7~10工作日技术合规审核实录》(附Python源码)
开发语言·python·pandas
持敬chijing9 小时前
Python-数据类型-列表
开发语言·python·青少年编程
2601_9623010110 小时前
Python环境搭建及PyCharm破解使用技巧
python·pycharm·环境搭建·避坑技巧·破解使用
Navigator_Z11 小时前
LeetCode //C - 1240. Tiling a Rectangle with the Fewest Squares
c语言·算法·leetcode
稻米哟11 小时前
力扣100——双指针
算法·leetcode
2601_9620994611 小时前
Python中的find()函数:用法和示例
python·字符串·索引·子字符串·find函数