1781. Sum of Beauty of All Substrings Medium
1/**
2 * [1781] Sum of Beauty of All Substrings
3 *
4 * The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.
5 *
6 * For example, the beauty of "abaacc" is 3 - 1 = 2.
7 *
8 * Given a string s, return the sum of beauty of all of its substrings.
9 *
10 * Example 1:
11 *
12 * Input: s = "aabcb"
13 * Output: 5
14 * Explanation: The substrings with non-zero beauty are ["aab","aabc","aabcb","abcb","bcb"], each with beauty equal to 1.
15 * Example 2:
16 *
17 * Input: s = "aabcbaa"
18 * Output: 17
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= s.length <=^ 500
24 * s consists of only lowercase English letters.
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/sum-of-beauty-of-all-substrings/
30// discuss: https://leetcode.com/problems/sum-of-beauty-of-all-substrings/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn beauty_sum(s: String) -> i32 {
36 0
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_1781() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.