DevYoon
[ํ๋ก๊ทธ๋๋จธ์ค] ์ฌํ๊ฒฝ๋ก (Python) ๋ณธ๋ฌธ
link ๐ https://programmers.co.kr/learn/courses/30/lessons/43164
from copy import deepcopy
def solution(tickets):
tickets.sort(key=lambda x:(x[0], x[1]))
answer = []
check = [0]*len(tickets)
flag = 0
def dfs(level, airport, path):
nonlocal tickets, answer, flag
if level == len(tickets):
flag = 1
answer = deepcopy(path)
return
if flag:
return
for idx in range(len(tickets)):
if check[idx] == 0:
if tickets[idx][0] == airport:
check[idx] = 1
path.append(tickets[idx][1])
dfs(level+1, tickets[idx][1], path)
check[idx] = 0
path.pop()
dfs(0, "ICN", ["ICN"])
return answer