Skip to content

Commit 449c99b

Browse files
authored
Create count-the-number-of-consistent-strings.cpp
1 parent f6f14d9 commit 449c99b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int countConsistentStrings(string allowed, vector<string>& words) {
7+
int result = size(words);
8+
vector<bool> lookup(26);
9+
for (const auto& c: allowed) {
10+
lookup[c - 'a'] = true;
11+
}
12+
for (const auto& word: words) {
13+
for (const auto& c: word) {
14+
if (!lookup[c - 'a']) {
15+
--result;
16+
break;
17+
}
18+
}
19+
}
20+
return result;
21+
}
22+
};

0 commit comments

Comments
 (0)