Question
Test Case 1
Shell
복사
Test Case 2
Shell
복사
Solve
DFS
from collections import defaultdict
def solution(tickets):
path = defaultdict(list)
stack = ['ICN']
answer = []
for departure, arrival in tickets:
path[departure].append(arrival)
for departure in path.keys():
path[departure].sort(reverse=True)
while stack:
point = stack[-1]
if path[point]:
stack.append(path[point].pop())
else:
answer.append(stack.pop())
return answer[::-1]
Python
복사
실행시간 : ms