Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 냅색
- list
- 파이썬
- 8-queen
- 백준 1535
- dfs
- 백준 2606
- 9663
- 12865
- BFS
- 백준 9252
- 평범한 배낭
- python
- LCS2
- 백준_2178
- 프로그래머스
- 미로탐색
- 타겟 넘버
- 2606
- 리스트
- boj 11053
- 백준 12015
- 가장 긴 증가하는 부분수열
- 증가하는 부분수열 2
- 백준
- 데카르트 곱
- 알고리즘
- 소수찾기
- BOJ 2606
- 대소비교
Archives
- Today
- Total
Devlog_by_0giru
[프로그래머스] 여행 경로 본문
# 테스트 케이스 2 통과 / 실패
def solution(tickets):
nation_num = len(tickets)
graph = []
graph_new = []
result = []
for inf in tickets:
graph.append([inf[0]])
for inf in tickets:
for i in range(nation_num):
if inf[0] == graph[i][0]:
graph[i].append(inf[1])
for inf in graph:
if inf not in graph_new:
graph_new.append(inf)
for inf_new in graph_new:
temp1 = inf_new[0]
inf_new.sort()
temp2 = inf_new.index(temp1)
inf_new[0], inf_new[temp2] = inf_new[temp2], inf_new[0]
# 초기값 ICN 입력
result.append(graph_new[0][0])
while tickets:
for node in graph_new:
if node[0] == result[-1]:
depart = node[0]
arrival = node[1]
result.append(arrival)
temp_num1 = graph_new.index(node)
del graph_new[temp_num1][1]
for ticket in tickets:
if ticket[0] == depart and ticket[1] == arrival:
temp_num2 = tickets.index(ticket)
del tickets[temp_num2]
return result
테스트 케이스 2개는 통과했으나 제출시 25% 정확도 밖에 얻지 못했다.
dfs bfs로 문제가 분류되어있으나 이를 응용하지 못한것 같다.
다른 답안을 보고 공부할 예정이다.
'[PS]' 카테고리의 다른 글
[boj] 알파벳_1987 (0) | 2021.02.23 |
---|---|
[boj] 유기농 배추_1012 (0) | 2021.02.18 |
[boj] 단지 번호 붙이기_2667 (0) | 2021.02.13 |
[boj] 바이러스_2606 (0) | 2021.02.09 |
[boj] DFS와 BFS_1260 (0) | 2021.02.08 |