java.lang.Object
g1701_1800.s1781_sum_of_beauty_of_all_substrings.Solution

public class Solution extends Object
1781 - Sum of Beauty of All Substrings.<p>Medium</p> <p>The <strong>beauty</strong> of a string is the difference in frequencies between the most frequent and least frequent characters.</p> <ul> <li>For example, the beauty of <code>&quot;abaacc&quot;</code> is <code>3 - 1 = 2</code>.</li> </ul> <p>Given a string <code>s</code>, return <em>the sum of <strong>beauty</strong> of all of its substrings.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;aabcb&rdquo;</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> The substrings with non-zero beauty are [&ldquo;aab&rdquo;,&ldquo;aabc&rdquo;,&ldquo;aabcb&rdquo;,&ldquo;abcb&rdquo;,&ldquo;bcb&rdquo;], each with beauty equal to 1.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;aabcbaa&rdquo;</p> <p><strong>Output:</strong> 17</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 500</code></li> <li><code>s</code> consists of only lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • beautySum

      public int beautySum(String s)