Last active
September 5, 2018 02:14
-
-
Save Alexis117/97af151e1ad249b721c4783d3c0c5d6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python | |
def wordLadder (beginWord, endWord, wordList): | |
List2=[] | |
while beginWord != endWord: | |
count1=0 | |
count2=0 | |
List1=[] | |
for element in wordList: | |
for i in element: | |
if i not in beginWord: | |
count1=count1 + 1 | |
if count1 == 1 : | |
List1.append(element) | |
else: | |
count1=0 | |
comparador=0 | |
for i in List1: | |
for j in i: | |
if j in endWord: | |
count2=count2+1 | |
if count2 > comparador: | |
beginWord=i | |
if count2 == len(endWord)-1: | |
beginWord=endWord | |
comparador=count2 | |
print (beginWord) | |
if beginWord != endWord: | |
wordList.remove(beginWord) | |
List2.append(beginWord) | |
return List2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment