Skip to content

Commit

Permalink
Create 단어 변환 kyuhyun.py da-in#164
Browse files Browse the repository at this point in the history
  • Loading branch information
lalabulla authored Mar 13, 2023
1 parent 17c7659 commit aedf6cd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Programmers - 고득점 Kit/[DFS-BFS] 단어 변환/kyuhyun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def solution(begin, target, words):
visit = [0] * len(words)
st = []
answer = -1
leng = len(begin)

if target not in words:
return 0

st.append(begin)
while st:
wd = st.pop()
answer += 1

if wd == target :
return answer

for k in range(len(words)):
word = words[k]
count = 0
if visit[k] == 1:
continue
for i in range(leng):
if wd[i] == word[i]:
count += 1
if count == leng - 1:
st.append(word)
visit[k] = 1

0 comments on commit aedf6cd

Please sign in to comment.