We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1af8102 commit 977465dCopy full SHA for 977465d
1 file changed
live10/test104/문제3/박희경.py
@@ -1,16 +1,20 @@
1
+from collections import *
2
+
3
def solution(begin, target, words):
- answer = 0
4
5
if target not in words:
6
return 0
7
- alpha = []
8
- for word in words:
9
- alpha.append(list(map(str, word.rstrip())))
+ q = deque([(begin, 0)])
+ while q:
10
+ now, cnt = q.popleft()
11
+ if now == target:
12
+ return cnt
13
- def dfs(word, target):
- word = list(map(str, word.rstrip()))
-
14
15
16
- return answer
+ for word in words:
+ tmp_cnt = 0
+ 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