728x90
반응형
1. 문제
https://programmers.co.kr/learn/courses/30/lessons/43163
2. 코드
def dfs(begin, target, words, visited):
str_end = target
str_start = begin
int_depth = 0
arr_stack = [str_start]
while arr_stack:
str_top = arr_stack.pop()
print(str_top)
if str_top == target:
return int_depth
for i in range(len(words)):
if visited[i] or words[i] == str_top:
continue
for _ in range(len(words[i])):
count_tmp = 0
for j in range(len(words[i])):
if [ch for ch in words[i]][j] == [ch for ch in str_top][j]:
count_tmp+=1
if (len(words[i])-1) == count_tmp:
visited[i] = True
if words[i] != str_end:
arr_stack.append(words[i])
else:
return int_depth+1
break
int_depth += 1
def solution(begin, target, words):
if target not in words:
return 0
visited = [False] * (len(words))
print(words)
return dfs(begin, target, words, visited)
3. 결과
728x90
반응형
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스][Lv.1][Python] 3진법 뒤집기 (0) | 2022.09.20 |
---|---|
[프로그래머스][Lv.1][Python] 최대공약수와 최소공배수 (0) | 2022.09.20 |
[프로그래머스][SQL] 고득점 kit (0) | 2022.03.05 |
[프로그래머스][Lv.3][Cpp] 네트워크 (0) | 2022.02.06 |
[프로그래머스][Lv.2][Python] 타겟 넘버 (0) | 2022.02.06 |
[프로그래머스][Lv.1][Python] K번째 수 (0) | 2021.10.21 |
댓글