Class Solution
java.lang.Object
g1901_2000.s1915_number_of_wonderful_substrings.Solution
1915 - Number of Wonderful Substrings.<p>Medium</p>
<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><strong>Example 1:</strong></p>
<p><strong>Input:</strong> word = “aba”</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> The four wonderful substrings are underlined below:</p>
<ul>
<li>
<p>“<strong>a</strong>ba” -> “a”</p>
</li>
<li>
<p>“a<strong>b</strong>a” -> “b”</p>
</li>
<li>
<p>“ab<strong>a</strong>” -> “a”</p>
</li>
<li>
<p>“<strong>aba</strong>” -> “aba”</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> word = “aabb”</p>
<p><strong>Output:</strong> 9</p>
<p><strong>Explanation:</strong> The nine wonderful substrings are underlined below:</p>
<ul>
<li>
<p>“<strong>a</strong>abb” -> “a”</p>
</li>
<li>
<p>“<strong>aa</strong>bb” -> “aa”</p>
</li>
<li>
<p>“<strong>aab</strong>b” -> “aab”</p>
</li>
<li>
<p>“<strong>aabb</strong>” -> “aabb”</p>
</li>
<li>
<p>“a<strong>a</strong>bb” -> “a”</p>
</li>
<li>
<p>“a<strong>abb</strong>” -> “abb”</p>
</li>
<li>
<p>“aa<strong>b</strong>b” -> “b”</p>
</li>
<li>
<p>“aa<strong>bb</strong>” -> “bb”</p>
</li>
<li>
<p>“aab<strong>b</strong>” -> “b”</p>
</li>
</ul>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> word = “he”</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> The two wonderful substrings are underlined below:</p>
<ul>
<li>
<p>“<strong>h</strong>e” -> “h”</p>
</li>
<li>
<p>“h<strong>e</strong>” -> “e”</p>
</li>
</ul>
<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>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
wonderfulSubstrings
-