Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 16 Nov## Sum of Beauty of All Substrings
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public:
int beautySum(string s) {
// Your code goes here
int res = 0, n = s.length();
for (int i = 0; i < n; i++) {
vector<int> dp(26);
for (int j = i; j < n; j++) {
dp[s[j] - 'a']++;
int a = 0, b = n;
for (int k = 0; k < 26; k++) {
if (dp[k] > 0) {
a = max(a, dp[k]);
b = min(b, dp[k]);
}
}
res += a - b;
}
}
return res;
}
};