일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- attribute
- shiba
- data science
- Python Implementation
- kaggle
- 43. Multiply Strings
- Protocol
- concurrency
- Decorator
- Substring with Concatenation of All Words
- Python
- 밴픽
- LeetCode
- Regular Expression
- Convert Sorted List to Binary Search Tree
- 프로그래머스
- Python Code
- t1
- DWG
- 운영체제
- 시바견
- 109. Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- 30. Substring with Concatenation of All Words
- iterator
- 715. Range Module
- Class
- Generator
- 컴퓨터의 구조
- 파이썬
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 |