File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -217,6 +217,38 @@ public class Main {
217217```
218218
219219### Python
220+ ``` Python
221+ def judge (s1 ,s2 ):
222+ count= 0
223+ for i in range (len (s1)):
224+ if s1[i]!= s2[i]:
225+ count+= 1
226+ return count== 1
227+
228+ if __name__ == ' __main__' :
229+ n= int (input ())
230+ beginstr,endstr= map (str ,input ().split())
231+ if beginstr== endstr:
232+ print (0 )
233+ exit ()
234+ strlist= []
235+ for i in range (n):
236+ strlist.append(input ())
237+
238+ # use bfs
239+ visit= [False for i in range (n)]
240+ queue= [[beginstr,1 ]]
241+ while queue:
242+ str ,step= queue.pop(0 )
243+ if judge(str ,endstr):
244+ print (step+ 1 )
245+ exit ()
246+ for i in range (n):
247+ if visit[i]== False and judge(strlist[i],str ):
248+ visit[i]= True
249+ queue.append([strlist[i],step+ 1 ])
250+ print (0 )
251+ ```
220252
221253### Go
222254
You can’t perform that action at this time.
0 commit comments