-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1160.cpp
More file actions
27 lines (24 loc) · 710 Bytes
/
Copy path1160.cpp
File metadata and controls
27 lines (24 loc) · 710 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 {
static int count[27];
static inline bool valid(const string &word) {
static int cnt[27];
memset(cnt, 0x00, sizeof(count));
for (const char c : word) {
const int idx = c & 0x1F;
if (++cnt[idx] > count[idx]) return false;
}
return true;
}
public:
int countCharacters(const vector<string> &words, const string &chars) const {
memset(count, 0x00, sizeof(count));
for (const char c : chars)
count[c & 0x1F]++;
int res = 0;
for (const auto &word : words) {
if (valid(word)) res += word.size();
}
return res;
}
};
int Solution::count[27];