LC 127 Word Ladder(M)
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:
Only one letter can be changed at a time.
Each intermediate word must exist in the word list.
Note:
Return 0 if there is no such transformation sequence.
All words have the same length.
All words contain only lowercase alphabetic characters.
解体思路: BFS
这道题的解题方法就是BFS,而且有单向BFS和双向BFS两种
单向BFS:从起始的Word加入到队列当中,每次从队列中取出一个词,并加入词表中和他只差别一位且未使用的词 重复上述过程,直到当前取出的词可以一位变换到结束的词
双向BFS:交替开始词串,和结尾词串 队列。
Last updated
Was this helpful?