Medium
抽象题目大意
欧拉图的相关文档
建议草稿纸上演算一下,一图胜千言,参考解题:链接
以上,尝试一下代码,AC!
python3
class Solution:
def findItinerary(self, tickets: List[List[str]]) -> List[str]:
graph = collections.defaultdict(list)
for t in tickets:
graph[t[0]].append(t[1])
graph[t[0]].sort()
res = []
def helper(node):
while graph[node]:
helper(graph[node].pop(0))
res.append(node)
helper('JFK')
return res[::-1]