일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 프로그래머스
- 43. Multiply Strings
- Substring with Concatenation of All Words
- data science
- LeetCode
- Generator
- 시바견
- Decorator
- shiba
- t1
- 밴픽
- DWG
- Protocol
- Python Code
- Convert Sorted List to Binary Search Tree
- kaggle
- Python Implementation
- 파이썬
- Class
- 715. Range Module
- 109. Convert Sorted List to Binary Search Tree
- 컴퓨터의 구조
- 30. Substring with Concatenation of All Words
- attribute
- Regular Expression
- 운영체제
- iterator
- 315. Count of Smaller Numbers After Self
- Python
- concurrency
Archives
- Today
- Total
Scribbling
프로그래머스: 여행경로 본문
그냥...DFS로 푼다...
from collections import defaultdict
import copy
def solution(tickets):
tickets.sort()
# dictionary["ICN"] = ["ATL", "SFO"]
dictionary = defaultdict(list)
for ticket in tickets:
dictionary[ticket[0]].append(ticket[1])
def dfs(cur, dictionary, edges, path):
if not edges:
return path
for v in dictionary[cur]:
next_dictionary = copy.deepcopy(dictionary)
next_dictionary[cur].remove(v)
edges.remove([cur, v])
ret = dfs(v, next_dictionary, edges, path+[v])
if ret:
return ret
edges.append([cur, v])
return dfs("ICN", dictionary, tickets, ["ICN"])
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 116. Populating Next Right Pointers in Each Node (0) | 2021.11.02 |
---|---|
LeetCode: 114. Flatten Binary Tree to Linked List (0) | 2021.11.02 |
프로그래머스: 단어 변환 (0) | 2021.11.01 |
프로그래머스: 네트워크 (0) | 2021.10.31 |
프로그래머스: 타겟 넘버 (0) | 2021.10.31 |