Compare Strings by Frequency of the Smallest Character
给两个字符串组, 比较两个字符串组的最小char的频率. 我就直接做的, 我看答案有二叉搜索
class Solution {
public int[] numSmallerByFrequency(String[] queries, String[] words) {
int[] t = new int[words.length];
for(int i = 0; i < words.length; i++){
t[i] = count(words[i]);
}
int[] res = new int[queries.length];
for(int i = 0; i < queries.length; i++) {
int c = 0;
int tt = count(queries[i]);
for(int j = 0; j < t.length; j++) {
if(tt < t[j])
c++;
}
res[i] = c;
}
return res;
}
private int count (String s) {
char[] c = s.toCharArray();
Arrays.sort(c);
char t = c[0];
int count = 0;
for(int i = 0; i < c.length; i++){
if(t != c[i])
break;
count++;
}
return count;
}
}