Count the Number of Consistent Strings LeetCode solution in C++

1
class Solution {
2
public:
3
int countConsistentStrings(string allowed, vector<string> &words) {
4
// support variable
5
int res = words.size();
6
bool alpha[26] = {};
7
// populating alpha
8
for (char c : allowed) alpha[c - 'a'] = true;
9
// parsing all the words to see if each character is in alpha
10
for (string word : words) {
11
// in case we find an unallowed character, we decrease res and break
12
for (char c : word)
13
if (!alpha[c - 'a']) {
14
res--;
15
break;
16
}
17
}
18
return res;
19
}
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0