1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-25 17:50:26 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/子串的最大出现次数 [maximum-number-of-occurrences-of-a-substring].html

47 lines
1.6 KiB
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<p>给你一个字符串&nbsp;<code>s</code> ,请你返回满足以下条件且出现次数最大的&nbsp;<strong>任意</strong>&nbsp;子串的出现次数:</p>
<ul>
<li>子串中不同字母的数目必须小于等于 <code>maxLetters</code></li>
<li>子串的长度必须大于等于&nbsp;<code>minSize</code> 且小于等于&nbsp;<code>maxSize</code></li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>s = &quot;aababcaab&quot;, maxLetters = 2, minSize = 3, maxSize = 4
<strong>输出:</strong>2
<strong>解释:</strong>子串 &quot;aab&quot; 在原字符串中出现了 2 次。
它满足所有的要求2 个不同的字母,长度为 3 (在 minSize 和 maxSize 范围内)。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>s = &quot;aaaa&quot;, maxLetters = 1, minSize = 3, maxSize = 3
<strong>输出:</strong>2
<strong>解释:</strong>子串 &quot;aaa&quot; 在原字符串中出现了 2 次,且它们有重叠部分。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>s = &quot;aabcabcab&quot;, maxLetters = 2, minSize = 2, maxSize = 3
<strong>输出:</strong>3
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>s = &quot;abcde&quot;, maxLetters = 2, minSize = 3, maxSize = 3
<strong>输出:</strong>0
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10^5</code></li>
<li><code>1 &lt;= maxLetters &lt;= 26</code></li>
<li><code>1 &lt;= minSize &lt;= maxSize &lt;= min(26, s.length)</code></li>
<li><code>s</code>&nbsp;只包含小写英文字母。</li>
</ul>