Skip to content

Commit 977465d

Browse files
committed
104차 3번 문제 다시 풀이
1 parent 1af8102 commit 977465d

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
from collections import *
2+
13
def solution(begin, target, words):
2-
answer = 0
34

45
if target not in words:
56
return 0
67

7-
alpha = []
8-
for word in words:
9-
alpha.append(list(map(str, word.rstrip())))
8+
q = deque([(begin, 0)])
9+
while q:
10+
now, cnt = q.popleft()
11+
if now == target:
12+
return cnt
1013

11-
def dfs(word, target):
12-
word = list(map(str, word.rstrip()))
13-
14-
15-
16-
return answer
14+
for word in words:
15+
tmp_cnt = 0
16+
for i in range(len(now)):
17+
if now[i] != word[i]:
18+
tmp_cnt += 1
19+
if tmp_cnt == 1:
20+
q.append([word, cnt + 1])

0 commit comments

Comments
 (0)