-
Notifications
You must be signed in to change notification settings - Fork 1
/
16 NOV string
60 lines (27 loc) · 867 Bytes
/
16 NOV string
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Solution {
public:
int beautySum(string s) {
int n = s.size();
int res = 0;
int arr[n+1][26];
for(int i=0;i<26;i++) arr[0][i]=0;
for(int i=0;i<n;i++){
for(int j=0;j<26;j++){
arr[i+1][j]=arr[i][j];
}
arr[i+1][s[i]-'a']++;
}
for(int i=0;i<n+1;i++){
for(int j=i+1;j<n+1;j++){
int high=INT_MIN, low=INT_MAX;
for(int k=0;k<26;k++){
if(arr[j][k]-arr[i][k]==0) continue;
high=max(high, arr[j][k]-arr[i][k]);
low=min(low, arr[j][k]-arr[i][k]);
}
res+=high-low;
}
}
return res;
}
};