All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 06, 2024
Last updated : July 01, 2024
Related Topics : Array, Hash Table, String, Bit Manipulation
Acceptance Rate : 83.341 %
// Pure brute force
int countConsistentStrings(char * allowed, char ** words, int wordsSize){
int output = 0;
for (int i = 0; i < wordsSize; i++) {
char* word = words[i];
bool failed = true;
while (*word) {
failed = true;
char* allowedPtr = allowed;
while (*allowedPtr) {
if (*allowedPtr == *word) {
failed = false;
break;
}
allowedPtr++;
}
if (failed) {
break;
}
word++;
}
if (!failed) {
output++;
}
}
return output;
}
class Solution:
def countConsistentStrings(self, allowed: str, words: List[str]) -> int:
allowed = set(allowed)
output = len(words)
for word in words :
for c in word :
if c not in allowed :
output -= 1
break
return output