leetcode_1160
Solutions
class Solution {
public:
int countCharacters(vector<string>& words, string chars) {
vector<int> canuse(126);
for (auto c : chars)
canuse[c]++;
int res = 0;
for (auto & w : words) {
vector<int> need(126);
bool ok = true;
for (auto c : w)
if (++need[c] > canuse[c]) {
ok = false;
break;
}
if (ok) res += w.size();
}
return res;
}
};Last updated