-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path16_November.java
More file actions
33 lines (32 loc) · 842 Bytes
/
Copy path16_November.java
File metadata and controls
33 lines (32 loc) · 842 Bytes
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
class Solution {
public static int getBeauty(int freq[])
{
int minF = Integer.MAX_VALUE;
int maxF = Integer.MIN_VALUE;
for(int i = 1;i < 27;i++)
{
if(freq[i] != 0)
minF = Math.min(minF,freq[i]);
maxF = Math.max(maxF,freq[i]);
}
int beauty = maxF - minF;
return beauty;
}
public static int beautySum(String s) {
int n = s.length();
int sum = 0;
for(int i = 0;i < n;i++)
{
int freq[] = new int[27];
for(int j = i; j < n;j++)
{
char ch = s.charAt(j);
int ind = ch - 96;
freq[ind]++;
int beauty = getBeauty(freq);
sum += beauty;
}
}
return sum;
}
}