其他分享
首页 > 其他分享> > leetcode-332-重新安排行程

leetcode-332-重新安排行程

作者:互联网

题目描述:

 

方法:欧拉回路 dfs

class Solution:
    def findItinerary(self, tickets: List[List[str]]) -> List[str]:
        d = collections.defaultdict(list)
        for f,t in tickets:
            d[f] += [t]
        for f in d:
            d[f].sort()
        ans = []
        def dfs(f):
            while d[f]:
                dfs(d[f].pop(0))
            ans.insert(0,f)
        dfs("JFK")
        return ans
       

 

标签:tickets,List,dfs,332,重新安排,str,ans,leetcode,def
来源: https://www.cnblogs.com/oldby/p/11673558.html