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)/包含所有三种字符的子字符串数目 [number-of-substrings-containing-all-three-characters].html

35 lines
1.4 KiB
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<p>给你一个字符串 <code>s</code>&nbsp;,它只包含三种字符 a, b 和 c 。</p>
<p>请你返回 ab 和 c 都&nbsp;<strong>至少&nbsp;</strong>出现过一次的子字符串数目。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>s = &quot;abcabc&quot;
<strong>输出:</strong>10
<strong>解释:</strong>包含 ab 和 c 各至少一次的子字符串为<em> &quot;</em>abc<em>&quot;, &quot;</em>abca<em>&quot;, &quot;</em>abcab<em>&quot;, &quot;</em>abcabc<em>&quot;, &quot;</em>bca<em>&quot;, &quot;</em>bcab<em>&quot;, &quot;</em>bcabc<em>&quot;, &quot;</em>cab<em>&quot;, &quot;</em>cabc<em>&quot; </em><em> &quot;</em>abc<em>&quot; </em>(<strong>相同</strong><strong>字符串算多次</strong>)<em></em>
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>s = &quot;aaacb&quot;
<strong>输出:</strong>3
<strong>解释:</strong>包含 ab 和 c 各至少一次的子字符串为<em> &quot;</em>aaacb<em>&quot;, &quot;</em>aacb<em>&quot; </em><em> &quot;</em>acb<em>&quot;</em>
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>s = &quot;abc&quot;
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= s.length &lt;= 5 x 10^4</code></li>
<li><code>s</code>&nbsp;只包含字符 ab 和 c 。</li>
</ul>