← 返回 amazon 的题目列表Shortest Word Ladder Transformation Length Calculation
类型:online_judge
amazon
Given a beginWord, an endWord, and a dictionary wordList, find the length of the shortest transformation sequence from beginWord to endWord. Each transformation can only change one letter at a time, and the new word must exist in the dictionary. Return 0 if no such sequence exists. Clearly define the variables and function signature.
Example:
Input:
beginWord = "hit"
endWord = "cog"
wordList = ["hot","dot","dog","lot","log","cog"]
Output:
5
Explanation: The shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog", with the length being 5.
Constraints:
All words in wordList have the same length.
All words are lowercase letters.
Consider beginWord even if it's not in the wordList.
Example
Input
hit
cog
hot
dot
dog
lot
log
cog