给定一个开头单词beginWord,一个结尾单词endWord,一个单词列表wordList,其中beginWord不在wordList中,而endWord在wordList中,这些单词都是等长的;
一个单词的一次转变表示其中的一个字母改变;所有转变的单词都在wordList中,试求从beginWord到endWord的最短路径长度;没有返回0;
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
广度优先搜索,先找到所有列表中一次能到达的单词,然后根据这些单词找到两次能到达的单词,直到找到为止
class Solution { public: bool judgeOneLetterDiffBetweenTwoWords(string firstword, string secondword){ int difftime = 0, len1 = firstword.length(), len2 = secondword.length(); if(len1 != len2){ return false; } if(len1 == 0){ return true; } char tmp1 = '