mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
43 lines
1.6 KiB
HTML
43 lines
1.6 KiB
HTML
|
<p>Given a string <code>s</code> and an integer <code>k</code>, return the total number of <span data-keyword="substring-nonempty">substrings</span> of <code>s</code> where <strong>at least one</strong> character appears <strong>at least</strong> <code>k</code> times.</p>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong class="example">Example 1:</strong></p>
|
||
|
|
||
|
<div class="example-block">
|
||
|
<p><strong>Input:</strong> <span class="example-io">s = "abacb", k = 2</span></p>
|
||
|
|
||
|
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||
|
|
||
|
<p><strong>Explanation:</strong></p>
|
||
|
|
||
|
<p>The valid substrings are:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li><code>"aba"</code> (character <code>'a'</code> appears 2 times).</li>
|
||
|
<li><code>"abac"</code> (character <code>'a'</code> appears 2 times).</li>
|
||
|
<li><code>"abacb"</code> (character <code>'a'</code> appears 2 times).</li>
|
||
|
<li><code>"bacb"</code> (character <code>'b'</code> appears 2 times).</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
|
||
|
<p><strong class="example">Example 2:</strong></p>
|
||
|
|
||
|
<div class="example-block">
|
||
|
<p><strong>Input:</strong> <span class="example-io">s = "abcde", k = 1</span></p>
|
||
|
|
||
|
<p><strong>Output:</strong> <span class="example-io">15</span></p>
|
||
|
|
||
|
<p><strong>Explanation:</strong></p>
|
||
|
|
||
|
<p>All substrings are valid because every character appears at least once.</p>
|
||
|
</div>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong>Constraints:</strong></p>
|
||
|
|
||
|
<ul>
|
||
|
<li><code>1 <= s.length <= 3000</code></li>
|
||
|
<li><code>1 <= k <= s.length</code></li>
|
||
|
<li><code>s</code> consists only of lowercase English letters.</li>
|
||
|
</ul>
|