LeetCode题解:Word Ladder

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
For example,

Given:
beginWord = “hit”
endWord = “cog”
wordList = [“hot”,”dot”,”dog”,”lot”,”log”]
As one shortest transformation is “hit” -> “hot” -> “dot” -> “dog” -> “cog”,
return its length 5.

Note:
Return 0 if there is no such transformation sequence.
All words have the same length.
All words contain only lowercase alphabetic characters.

题意:给定两个单词和字典,判断单词A是否能通过变换字典中的的单词,并不断向下变换为单词B

解决思路:修改单词中某个单词,然后看字典里是否存在该单词,存在则提取

代码:

public 

你可能感兴趣的:(LeetCode,LeetCode全题解,leetcode)