class Solution { public:// 判断c是否在chars 中存在bool strfind(string c,string chars){ for(int i=0;i<c.size();i++){ if(chars.find(c[i],0)!=-1){ chars.erase(chars.find(c[i],0),1);}else return false;}return true;}int countCharacters(vector<string>& words, string chars) { int res=0;for(int i=0;i<words.size();i++){ if(strfind(words[i],chars)){ res+=words[i].size();}}return res;} };
class Solution:def countCharacters(self, words: List[str], chars: str) -> int:data=[collections.Counter(i) for i in words]cnt=collections.Counter(chars)res=0for i, w in enumerate(data):for j,c in w.items():if cnt[j]<c:breakelse :res+=len(words[i])return res