[프로그래머스] 여행경로 - Python
programmers.co.kr/learn/courses/30/lessons/43164 코딩테스트 연습 - 여행경로 [[ICN, SFO], [ICN, ATL], [SFO, ATL], [ATL, ICN], [ATL,SFO]] [ICN, ATL, ICN, SFO, ATL, SFO] programmers.co.kr 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 route..
Algorithm/Programmers
2021. 1. 4. 15:01