mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
28 lines
1.1 KiB
HTML
28 lines
1.1 KiB
HTML
<p>Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step must be in the dictionary.</p>
|
|
|
|
|
|
|
|
<p>Write code to return a possible transforming sequence. If there is more than one sequence, return any of them.</p>
|
|
|
|
|
|
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong>
|
|
|
|
beginWord = "hit",
|
|
|
|
endWord = "cog",
|
|
|
|
wordList = ["hot","dot","dog","lot","log","cog"]
|
|
|
|
|
|
|
|
<strong>Output:</strong>
|
|
|
|
["hit","hot","dot","lot","log","cog"]
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong>
|
|
|
|
beginWord = "hit"
|
|
|
|
endWord = "cog"
|
|
|
|
wordList = ["hot","dot","dog","lot","log"]
|
|
|
|
|
|
|
|
<strong>Output: </strong>[]
|
|
|
|
|
|
|
|
<strong>Explanation:</strong> <em>endWord</em> "cog" is not in the dictionary, so there's no possible transforming sequence.</pre>
|
|
|