Skip to content

Instantly share code, notes, and snippets.

@Alexis117
Last active September 5, 2018 02:14
Show Gist options
  • Save Alexis117/97af151e1ad249b721c4783d3c0c5d6c to your computer and use it in GitHub Desktop.
Save Alexis117/97af151e1ad249b721c4783d3c0c5d6c to your computer and use it in GitHub Desktop.
#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