leetcode/0127.Word-Ladder/README.md
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:
Note:
Example 1:
Input:
beginWord = "hit",
endWord = "cog",
wordList = ["hot","dot","dog","lot","log","cog"]
Output: 5
Explanation: As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog",
return its length 5.
Example 2:
Input:
beginWord = "hit"
endWord = "cog"
wordList = ["hot","dot","dog","lot","log"]
Output: 0
Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
给定两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列的长度。转换需遵循如下规则:
说明:
beginWord 变换到 endWord 最短变换次数。可以用 BFS,从 beginWord 开始变换,把该单词的每个字母都用 'a'~'z' 变换一次,生成的数组到 wordList 中查找,这里用 Map 来记录查找。找得到就入队列,找不到就输出 0 。入队以后按照 BFS 的算法依次遍历完,当所有单词都 len(queue)<=0 出队以后,整个程序结束。wordList 中