class Solution { public: int countCharacters(vector<string>& words, string chars) { unordered_map<char,int>mpchar; for(char c:chars){ mpchar[c]++; } int cnt = 0; for(auto wc:words){ unordered_map<char,int>mpwc; for(char c:wc){ mpwc[c]++; } bool flag = true; for(auto it:mpwc){ if(mpchar[it.first] < mpwc[it.first]){ flag = false; } } if(flag == true){ cnt += wc.size(); } } return cnt; } };
——————