๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/43164/solution_groups?language=python3
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 3๋จ๊ณ - ์ฌํ ๊ฒฝ๋ก
from collections import defaultdict
def solution(tickets):
path = []
graph = defaultdict(list)
for (start, end) in tickets:
graph[start].append(end)
for airport in graph.keys():
graph[airport].sort(reverse=True)
stack = ['ICN']
while stack:
top = stack.pop()
if top not in graph or not graph[top]:
path.append(top)
else:
stack.append(top)
stack.append(graph[top].pop())
return path[::-1]
DFS ๋ฅผ ํตํด ํ ์ ์๋ ๋ฌธ์ ์ด๋ค.
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
โฌ [Programmers] [Java] [Level2] ์ต๋๊ฐ๊ณผ ์ต์๊ฐ (0) | 2023.12.14 |
---|---|
โฌ [Programmers] [Java] [Level1] ์๋ฆฟ์ ๋ํ๊ธฐ (0) | 2023.12.11 |
โฌ [Programmers] [Python] [Level2] ์นด๋ ๋ญ์น (1) | 2023.05.10 |
โฌ [Programmers] [Python] [Level2] ์นด๋ ๋ญ์น (0) | 2023.04.17 |
โฌ [Programmers] [Python] [Level2] ๋ ๋งต๊ฒ (0) | 2023.04.17 |