mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 14:57:08 +00:00
Time: 48 ms (74.71%), Space: 12.3 MB (36.78%) - LeetHub
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
int countConsistentStrings(char * allowed, char ** words, int wordsSize){
|
||||
|
||||
bool allowedFilter[26] = {false};
|
||||
for (char *c = allowed; *c != '\0'; ++c) {
|
||||
allowedFilter[*c - 'a'] = true;
|
||||
}
|
||||
|
||||
int numAllowedWords = 0;
|
||||
for (int i = 0; i < wordsSize; ++i) {
|
||||
bool allowedWord = true;
|
||||
for (char* a = words[i]; *a != '\0'; ++a) {
|
||||
if (!allowedFilter[*a - 'a']) {
|
||||
allowedWord = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allowedWord) {
|
||||
++numAllowedWords;
|
||||
}
|
||||
}
|
||||
return numAllowedWords;
|
||||
}
|
||||
Reference in New Issue
Block a user