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)/含有所有字符的最短字符串 [M1oyTv].html
2022-03-29 12:43:11 +08:00

48 lines
1.9 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>给定两个字符串 <code>s</code>&nbsp;<code>t</code> 。返回 <code>s</code> 中包含&nbsp;<code>t</code>&nbsp;的所有字符的最短子字符串。如果 <code>s</code> 中不存在符合条件的子字符串,则返回空字符串 <code>&quot;&quot;</code></p>
<p>如果 <code>s</code> 中存在多个符合条件的子字符串,返回任意一个。</p>
<p>&nbsp;</p>
<p><strong>注意: </strong>对于 <code>t</code> 中重复字符,我们寻找的子字符串中该字符数量必须不少于 <code>t</code> 中该字符数量。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = &quot;ADOBECODEBANC&quot;, t = &quot;ABC&quot;
<strong>输出:</strong>&quot;BANC&quot;
<strong>解释:</strong>最短子字符串 &quot;BANC&quot; 包含了字符串 t 的所有字符 &#39;A&#39;&#39;B&#39;&#39;C&#39;</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = &quot;a&quot;, t = &quot;a&quot;
<strong>输出:</strong>&quot;a&quot;
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = &quot;a&quot;, t = &quot;aa&quot;
<strong>输出:</strong>&quot;&quot;
<strong>解释:</strong>t 中两个字符 &#39;a&#39; 均应包含在 s 的子串中,因此没有符合条件的子字符串,返回空字符串。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length, t.length &lt;= 10<sup>5</sup></code></li>
<li><code>s</code><code>t</code> 由英文字母组成</li>
</ul>
<p>&nbsp;</p>
<p><strong>进阶:</strong>你能设计一个在 <code>o(n)</code> 时间内解决此问题的算法吗?</p>
<p>&nbsp;</p>
<p><meta charset="UTF-8" />注意:本题与主站 76&nbsp;题相似(本题答案不唯一):<a href="https://leetcode-cn.com/problems/minimum-window-substring/">https://leetcode-cn.com/problems/minimum-window-substring/</a></p>