-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1160.cpp
More file actions
32 lines (30 loc) · 750 Bytes
/
1160.cpp
File metadata and controls
32 lines (30 loc) · 750 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 res = 0;
map<char, int> rec;
for(int i = 0; i < chars.size(); i++) {
rec[chars[i]]++;
}
for(int i = 0; i < words.size(); i++)
{
string s = words[i];
map<char, int> word;
for(int j = 0; j < s.size(); j++) {
word[s[j]]++;
}
bool isHave = true;
for(int j = 0; j < s.size(); j++) {
if(word[s[j]] > rec[s[j]]) {
isHave = false;
}
}
if(isHave) {
res += s.size();
}
}
return res;
}
};