티스토리 뷰
programmers.co.kr/learn/courses/30/lessons/43164
def solution(tickets):
answer = []
tickets.sort(reverse=True)
routes = {}
for t1, t2 in tickets:
if t1 in routes:
routes[t1].append(t2)
else:
routes[t1] = [t2]
stack = ['ICN']
while stack:
top = stack[-1]
if top not in routes or len(routes[top]) == 0:
answer.append(stack.pop())
else:
stack.append(routes[top].pop())
answer.reverse()
return answer
'Algorithm > Programmers' 카테고리의 다른 글
[프로그래머스] 보호소에서 중성화한 동물 - MySQL (0) | 2021.02.12 |
---|---|
[프로그래머스] 오랜 기간 보호한 동물(1) - MySQL (0) | 2021.02.12 |
[프로그래머스] 두 개 뽑아서 더하기 - Python (0) | 2020.09.26 |
[프로그래머스] 같은 숫자는 싫어 - Python (0) | 2020.07.14 |
[프로그래머스] 위장 - Python (0) | 2020.07.12 |