Skip to content

Commit ec6ebf9

Browse files
Create 1781. Sum of Beauty of All Substrings.cpp
1 parent 632519e commit ec6ebf9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int beautySum(string s) {
4+
int ans = 0 , n = s.size();
5+
6+
for(int i = 0 ; i < n; i++){
7+
unordered_map<char,int>mp;
8+
for(int j = i; j < n ; j++){
9+
mp[s[j]]++;
10+
11+
int maxfreq = INT_MIN;
12+
int minfreq = INT_MAX;
13+
14+
for(auto it: mp){
15+
maxfreq = max(maxfreq, it.second);
16+
minfreq = min(minfreq, it.second);
17+
}
18+
ans += maxfreq - minfreq;
19+
}
20+
}
21+
return ans;
22+
}
23+
};

0 commit comments

Comments
 (0)