day17(拼写单词)
class Solution {
public int countCharacters(String[] words, String chars) {
int[] hash = new int[26];
for(char c:chars.toCharArray()){
hash[c-'a'] += 1;
}
int[] map = new int[26];
int len = 0;
for(int i=0;i<words.length;i++){
String word = words[i];
Arrays.fill(map,0);
boolean flag = true;
for(char c:words[i].toCharArray()){
map[c-'a'] ++;
if(map[c-'a']>hash[c-'a']){
flag = false;
}
}
if(flag){
len+=word.length();
}else{
len+=0;
}
}
return len;
}
}