-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1116.cpp
More file actions
31 lines (26 loc) · 723 Bytes
/
1116.cpp
File metadata and controls
31 lines (26 loc) · 723 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
28
29
30
31
class Solution {
public:
int countCharacters(vector<string>& words, string chars) {
int sum = 0;
vector<int> freq(26, 0);
for(char c : chars) {
freq[c - 'a']++;
}
for(int wordIndex = 0; wordIndex < words.size(); wordIndex++) {
vector<int> freqCopy = freq;
string word = words[wordIndex];
bool good = true;
for(char c : word) {
if(--freqCopy[c - 'a'] < 0) {
good = false;
break;
}
}
if(good) {
cout << word.size();
sum += word.size();
}
}
return sum;
}
};