java.lang.Object
g0801_0900.s0828_count_unique_characters_of_all_substrings_of_a_given_string.Solution

public class Solution extends Object
828 - Count Unique Characters of All Substrings of a Given String.<p>Hard</p> <p>Let&rsquo;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 = &quot;LEETCODE&quot;</code> then <code>&quot;L&quot;</code>, <code>&quot;T&quot;</code>, <code>&quot;C&quot;</code>, <code>&quot;O&quot;</code>, <code>&quot;D&quot;</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 = &ldquo;ABC&rdquo;</p> <p><strong>Output:</strong> 10</p> <p><strong>Explanation:</strong> All possible substrings are: &ldquo;A&rdquo;,&ldquo;B&rdquo;,&ldquo;C&rdquo;,&ldquo;AB&rdquo;,&ldquo;BC&rdquo; and &ldquo;ABC&rdquo;.</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 = &ldquo;ABA&rdquo;</p> <p><strong>Output:</strong> 8</p> <p><strong>Explanation:</strong> The same as example 1, except <code>countUniqueChars</code>(&ldquo;ABA&rdquo;) = 1.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;LEETCODE&rdquo;</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 Details

    • Solution

      public Solution()
  • Method Details

    • uniqueLetterString

      public int uniqueLetterString(String s)