1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/单词接龙 [om3reC].html

46 lines
2.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>在字典(单词列表)&nbsp;<code>wordList</code> 中,从单词 <code>beginWord</code><em>&nbsp;</em><code>endWord</code><strong>转换序列 </strong>是一个按下述规格形成的序列:</p>
<ul>
<li>序列中第一个单词是 <code>beginWord</code></li>
<li>序列中最后一个单词是 <code>endWord</code></li>
<li>每次转换只能改变一个字母。</li>
<li>转换过程中的中间单词必须是字典&nbsp;<code>wordList</code> 中的单词。</li>
</ul>
<p>给定两个长度相同但内容不同的单词<em> </em><code>beginWord</code><em>&nbsp;</em><code>endWord</code> 和一个字典 <code>wordList</code> ,找到从&nbsp;<code>beginWord</code>&nbsp;<code>endWord</code><strong>最短转换序列</strong> 中的 <strong>单词数目</strong> 。如果不存在这样的转换序列,返回 0。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>beginWord = &quot;hit&quot;, endWord = &quot;cog&quot;, wordList = [&quot;hot&quot;,&quot;dot&quot;,&quot;dog&quot;,&quot;lot&quot;,&quot;log&quot;,&quot;cog&quot;]
<strong>输出:</strong>5
<strong>解释:</strong>一个最短转换序列是 &quot;hit&quot; -&gt; &quot;hot&quot; -&gt; &quot;dot&quot; -&gt; &quot;dog&quot; -&gt; &quot;cog&quot;, 返回它的长度 5。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>beginWord = &quot;hit&quot;, endWord = &quot;cog&quot;, wordList = [&quot;hot&quot;,&quot;dot&quot;,&quot;dog&quot;,&quot;lot&quot;,&quot;log&quot;]
<strong>输出:</strong>0
<strong>解释:</strong>endWord &quot;cog&quot; 不在字典中,所以无法进行转换。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= beginWord.length &lt;= 10</code></li>
<li><code>endWord.length == beginWord.length</code></li>
<li><code>1 &lt;= wordList.length &lt;= 5000</code></li>
<li><code>wordList[i].length == beginWord.length</code></li>
<li><code>beginWord</code><code>endWord</code><code>wordList[i]</code> 由小写英文字母组成</li>
<li><code>beginWord != endWord</code></li>
<li><code>wordList</code> 中的所有字符串 <strong>互不相同</strong></li>
</ul>
<p>&nbsp;</p>
<p><meta charset="UTF-8" />注意:本题与主站 127&nbsp;题相同:&nbsp;<a href="https://leetcode-cn.com/problems/word-ladder/">https://leetcode-cn.com/problems/word-ladder/</a></p>