Skip to content

Commit bfebd5d

Browse files
Merge pull request #1 from Michael-Calce/Michael-Calce-patch-1
Create 16 NOV string
2 parents 3b0e354 + 37bb61d commit bfebd5d

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

16 NOV string

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
class Solution {
2+
public:
3+
int beautySum(string s) {
4+
5+
int n = s.size();
6+
7+
int res = 0;
8+
9+
10+
11+
int arr[n+1][26];
12+
13+
14+
15+
for(int i=0;i<26;i++) arr[0][i]=0;
16+
17+
18+
19+
for(int i=0;i<n;i++){
20+
21+
for(int j=0;j<26;j++){
22+
23+
arr[i+1][j]=arr[i][j];
24+
25+
}
26+
27+
arr[i+1][s[i]-'a']++;
28+
29+
}
30+
31+
32+
33+
for(int i=0;i<n+1;i++){
34+
35+
for(int j=i+1;j<n+1;j++){
36+
37+
int high=INT_MIN, low=INT_MAX;
38+
39+
40+
41+
for(int k=0;k<26;k++){
42+
if(arr[j][k]-arr[i][k]==0) continue;
43+
high=max(high, arr[j][k]-arr[i][k]);
44+
low=min(low, arr[j][k]-arr[i][k]);
45+
}
46+
47+
48+
49+
res+=high-low;
50+
51+
}
52+
53+
}
54+
55+
56+
57+
return res;
58+
59+
}
60+
};

0 commit comments

Comments
 (0)