-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1160.cpp
More file actions
27 lines (25 loc) · 698 Bytes
/
1160.cpp
File metadata and controls
27 lines (25 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
int countCharacters(vector<string>& words, string chars) {
vector<int> charHash(26, 0);
for (auto c : chars) {
charHash[c - 'a']++;
}
int res = 0;
for (auto& word : words) {
vector<int> wordHash(26, 0);
for (auto c : word) {
wordHash[c - 'a']++;
}
bool flag = true;
for (int i = 0; i < 26; ++i) {
if (wordHash[i] > charHash[i]) {
flag = false;
break;
}
}
if (flag) res += word.size();
}
return res;
}
};