Unique Substrings With Equal Digit Frequency
给一个string, 求unique的相同字频的子字符串.
这题吧, 我看用rolling hash做能快点, 但是我用的count做的.
class Solution {
public int equalDigitFrequency(String s) {
Set<String> set = new HashSet<>();
int n = s.length();
for(int i = 0; i < n; i++) {
int[] count = new int[26];
for(int j = i; j < n; j++) {
count[s.charAt(j) - '0']++;
if(check(count))
set.add(s.substring(i, j + 1));
}
}
return set.size();
}
public boolean check(int[] count) {
int nn = -1;
for(int n : count){
if(n != 0)
{
if(nn == -1)
nn = n;
else{
if(nn != n)
return false;
}
}
}
return true;
}
}