1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计完全子字符串 [count-complete-substrings].html
2023-12-09 01:16:38 +08:00

41 lines
2.0 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>给你一个字符串&nbsp;<code>word</code>&nbsp;和一个整数 <code>k</code>&nbsp;</p>
<p>如果&nbsp;<code>word</code>&nbsp;的一个子字符串 <code>s</code>&nbsp;满足以下条件,我们称它是 <strong>完全字符串:</strong></p>
<ul>
<li><code>s</code>&nbsp;中每个字符 <strong>恰好</strong>&nbsp;出现 <code>k</code>&nbsp;次。</li>
<li>相邻字符在字母表中的顺序 <strong>至多</strong>&nbsp;相差&nbsp;<code>2</code>&nbsp;。也就是说,<code>s</code>&nbsp;中两个相邻字符&nbsp;<code>c1</code>&nbsp;<code>c2</code>&nbsp;,它们在字母表中的位置相差<strong>&nbsp;至多</strong>&nbsp;<code>2</code></li>
</ul>
<p>请你返回 <code>word</code>&nbsp;<strong>完全</strong>&nbsp;子字符串的数目。</p>
<p><strong>子字符串</strong>&nbsp;指的是一个字符串中一段连续 <strong>非空</strong>&nbsp;的字符序列。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>word = "igigee", k = 2
<b>输出:</b>3
<b>解释:</b>完全子字符串需要满足每个字符恰好出现 2 次,且相邻字符相差至多为 2 <em><strong>igig</strong></em>ee, igig<strong style="font-style: italic;">ee</strong>, <em><strong>igigee</strong>&nbsp;</em>
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>word = "aaabbbccc", k = 3
<b>输出:</b>6
<b>解释:</b>完全子字符串需要满足每个字符恰好出现 3 次,且相邻字符相差至多为 2 <em><strong>aaa</strong></em>bbbccc, aaa<em><strong>bbb</strong></em>ccc, aaabbb<em><strong>ccc</strong></em>, <em><strong>aaabbb</strong></em>ccc, aaa<em><strong>bbbccc</strong></em>, <em><strong>aaabbbccc </strong></em>
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= word.length &lt;= 10<sup>5</sup></code></li>
<li><code>word</code>&nbsp;只包含小写英文字母。</li>
<li><code>1 &lt;= k &lt;= word.length</code></li>
</ul>