desc.html 1.3 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<p>给出两个字符串&nbsp;<code>str1</code>&nbsp;<code>str2</code>,返回同时以&nbsp;<code>str1</code>&nbsp;&nbsp;<code>str2</code>&nbsp;作为子序列的最短字符串。如果答案不止一个,则可以返回满足条件的任意一个答案。</p>

<p>(如果从字符串 T 中删除一些字符(也可能不删除,并且选出的这些字符可以位于 T 中的&nbsp;<strong>任意位置</strong>),可以得到字符串 S,那么&nbsp;S 就是&nbsp;T 的子序列)</p>

<p>&nbsp;</p>

<p><strong>示例:</strong></p>

<pre><strong>输入:</strong>str1 = &quot;abac&quot;, str2 = &quot;cab&quot;
<strong>输出:</strong>&quot;cabac&quot;
<strong>解释:</strong>
str1 = &quot;abac&quot;&quot;cabac&quot; 的一个子串,因为我们可以删去 &quot;cabac&quot; 的第一个 &quot;c&quot;得到 &quot;abac&quot;
str2 = &quot;cab&quot;&quot;cabac&quot; 的一个子串,因为我们可以删去 &quot;cabac&quot; 末尾的 &quot;ac&quot; 得到 &quot;cab&quot;
最终我们给出的答案是满足上述属性的最短字符串。
</pre>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ol>
	<li><code>1 &lt;= str1.length, str2.length &lt;= 1000</code></li>
	<li><code>str1</code>&nbsp;<code>str2</code>&nbsp;都由小写英文字母组成。</li>
</ol>