# BFS 이용
from collections import deque
def solution(begin, target, words):
answer = 0
# 방문 처리를 위한
visited = [False] * len(words)
q = deque()
q.append([begin,0])
while q:
word, cnt = q.popleft()
if word == target:
answer = cnt
break
for i in range(len(words)):
# 글자 차이
diff = 0
# 방문하지않았다면,
if not visited[i]:
# word[0] = h,i,t
for j in range(len(word)):
# words[0] = hot
if word[j] != words[i][j]:
diff += 1
if diff == 1:
q.append([words[i], cnt +1 ])
visited[i] = True
return answer