1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/最长字符串链 [longest-string-chain].html
2022-03-29 12:43:11 +08:00

48 lines
2.3 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>words</code>&nbsp;,其中每个单词都由小写英文字母组成。</p>
<p>如果我们可以&nbsp;<strong>不改变其他字符的顺序&nbsp;</strong>,在 <code>word<sub>A</sub></code>&nbsp;的任何地方添加 <strong>恰好一个</strong> 字母使其变成&nbsp;<code>word<sub>B</sub></code>&nbsp;,那么我们认为&nbsp;<code>word<sub>A</sub></code>&nbsp;&nbsp;<code>word<sub>B</sub></code>&nbsp;<strong>前身</strong></p>
<ul>
<li>例如,<code>"abc"</code>&nbsp;&nbsp;<code>"abac"</code>&nbsp;<strong>前身</strong>&nbsp;,而&nbsp;<code>"cba"</code>&nbsp;不是&nbsp;<code>"bcad"</code>&nbsp;<strong>前身</strong></li>
</ul>
<p><strong>词链</strong>是单词&nbsp;<code>[word_1, word_2, ..., word_k]</code>&nbsp;组成的序列,<code>k &gt;= 1</code>,其中&nbsp;<code>word<sub>1</sub></code>&nbsp;&nbsp;<code>word<sub>2</sub></code>&nbsp;的前身,<code>word<sub>2</sub></code>&nbsp;&nbsp;<code>word<sub>3</sub></code>&nbsp;的前身,依此类推。一个单词通常是 <code>k == 1</code><strong>单词链</strong>&nbsp;</p>
<p>从给定单词列表 <code>words</code> 中选择单词组成词链,返回 词链的&nbsp;<strong>最长可能长度</strong><br />
&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>words = ["a","b","ba","bca","bda","bdca"]
<strong>输出:</strong>4
<strong>解释:</strong>最长单词链之一为 ["a","<u>b</u>a","b<u>d</u>a","bd<u>c</u>a"]
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<b>输入:</b>words = ["xbc","pcxbcf","xb","cxbc","pcxbc"]
<b>输出:</b>5
<b>解释:</b>所有的单词都可以放入单词链 ["xb", "xb<u>c</u>", "<u>c</u>xbc", "<u>p</u>cxbc", "pcxbc<u>f</u>"].
</pre>
<p><strong>示例&nbsp;3:</strong></p>
<pre>
<b>输入:</b>words = ["abcd","dbqca"]
<strong>输出:</strong>1
<b>解释:</b>字链["abcd"]是最长的字链之一。
["abcd""dbqca"]不是一个有效的单词链,因为字母的顺序被改变了。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= words.length &lt;= 1000</code></li>
<li><code>1 &lt;= words[i].length &lt;= 16</code></li>
<li><code>words[i]</code>&nbsp;仅由小写英文字母组成。</li>
</ul>