Class Solution
java.lang.Object
g0801_0900.s0828_count_unique_characters_of_all_substrings_of_a_given_string.Solution
828 - Count Unique Characters of All Substrings of a Given String.<p>Hard</p>
<p>Let’s define a function <code>countUniqueChars(s)</code> that returns the number of unique characters on <code>s</code>.</p>
<ul>
<li>For example if <code>s = "LEETCODE"</code> then <code>"L"</code>, <code>"T"</code>, <code>"C"</code>, <code>"O"</code>, <code>"D"</code> are the unique characters since they appear only once in <code>s</code>, therefore <code>countUniqueChars(s) = 5</code>.</li>
</ul>
<p>Given a string <code>s</code>, return the sum of <code>countUniqueChars(t)</code> where <code>t</code> is a substring of s.</p>
<p>Notice that some substrings can be repeated so in this case you have to count the repeated ones too.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “ABC”</p>
<p><strong>Output:</strong> 10</p>
<p><strong>Explanation:</strong> All possible substrings are: “A”,“B”,“C”,“AB”,“BC” and “ABC”.</p>
<p>Evey substring is composed with only unique letters.</p>
<p>Sum of lengths of all substring is 1 + 1 + 1 + 2 + 2 + 3 = 10</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “ABA”</p>
<p><strong>Output:</strong> 8</p>
<p><strong>Explanation:</strong> The same as example 1, except <code>countUniqueChars</code>(“ABA”) = 1.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “LEETCODE”</p>
<p><strong>Output:</strong> 92</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 10</code><sup>5</sup></li>
<li><code>s</code> consists of uppercase English letters only.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
uniqueLetterString
-