体验新版 GitCode,发现更多精彩内容 >>
<p>给出两个字符串 <code>str1</code> 和 <code>str2</code>,返回同时以 <code>str1</code> 和 <code>str2</code> 作为子序列的最短字符串。如果答案不止一个,则可以返回满足条件的任意一个答案。</p> <p>(如果从字符串 T 中删除一些字符(也可能不删除,并且选出的这些字符可以位于 T 中的 <strong>任意位置</strong>),可以得到字符串 S,那么 S 就是 T 的子序列)</p> <p> </p> <p><strong>示例:</strong></p> <pre><strong>输入:</strong>str1 = "abac", str2 = "cab" <strong>输出:</strong>"cabac" <strong>解释:</strong> str1 = "abac" 是 "cabac" 的一个子串,因为我们可以删去 "cabac" 的第一个 "c"得到 "abac"。 str2 = "cab" 是 "cabac" 的一个子串,因为我们可以删去 "cabac" 末尾的 "ac" 得到 "cab"。 最终我们给出的答案是满足上述属性的最短字符串。 </pre> <p> </p> <p><strong>提示:</strong></p> <ol> <li><code>1 <= str1.length, str2.length <= 1000</code></li> <li><code>str1</code> 和 <code>str2</code> 都由小写英文字母组成。</li> </ol>