mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
57 lines
2.7 KiB
HTML
57 lines
2.7 KiB
HTML
<p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<p>Given a string <code>word</code> that consists of the first ten lowercase English letters (<code>'a'</code> through <code>'j'</code>), return <em>the <strong>number of wonderful non-empty substrings</strong> in </em><code>word</code><em>. If the same substring appears multiple times in </em><code>word</code><em>, then count <strong>each occurrence</strong> separately.</em></p>
|
|
|
|
|
|
|
|
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong> word = "aba"
|
|
|
|
<strong>Output:</strong> 4
|
|
|
|
<strong>Explanation:</strong> The four wonderful substrings are underlined below:
|
|
|
|
- "<u><strong>a</strong></u>ba" -> "a"
|
|
|
|
- "a<u><strong>b</strong></u>a" -> "b"
|
|
|
|
- "ab<u><strong>a</strong></u>" -> "a"
|
|
|
|
- "<u><strong>aba</strong></u>" -> "aba"
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong> word = "aabb"
|
|
|
|
<strong>Output:</strong> 9
|
|
|
|
<strong>Explanation:</strong> The nine wonderful substrings are underlined below:
|
|
|
|
- "<strong><u>a</u></strong>abb" -> "a"
|
|
|
|
- "<u><strong>aa</strong></u>bb" -> "aa"
|
|
|
|
- "<u><strong>aab</strong></u>b" -> "aab"
|
|
|
|
- "<u><strong>aabb</strong></u>" -> "aabb"
|
|
|
|
- "a<u><strong>a</strong></u>bb" -> "a"
|
|
|
|
- "a<u><strong>abb</strong></u>" -> "abb"
|
|
|
|
- "aa<u><strong>b</strong></u>b" -> "b"
|
|
|
|
- "aa<u><strong>bb</strong></u>" -> "bb"
|
|
|
|
- "aab<u><strong>b</strong></u>" -> "b"
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p><strong>Example 3:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong> word = "he"
|
|
|
|
<strong>Output:</strong> 2
|
|
|
|
<strong>Explanation:</strong> The two wonderful substrings are underlined below:
|
|
|
|
- "<b><u>h</u></b>e" -> "h"
|
|
|
|
- "h<strong><u>e</u></strong>" -> "e"
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li><code>1 <= word.length <= 10<sup>5</sup></code></li>
|
|
|
|
<li><code>word</code> consists of lowercase English letters from <code>'a'</code> to <code>'j'</code>.</li>
|
|
|
|
</ul> |