DevYoon
[ํ๋ก๊ทธ๋๋จธ์ค] ๋จ์ด ๋ณํ (Python) ๋ณธ๋ฌธ
link ๐ https://programmers.co.kr/learn/courses/30/lessons/43163
def solution(begin, target, words):
if target not in words:
answer = 0
else:
def bfs(start, level):
q = []
q.append((start, level))
while q:
nowwords, level = q.pop(0)
if nowwords == target:
return level
for word in words:
temp = [0]*len(word)
for idx in range(len(word)):
if nowwords[idx] != word[idx]:
temp[idx] = 1
if sum(temp) == 1:
q.append((word, level+1))
answer = bfs(begin, 0)
return answer