diff --git a/1684-count-the-number-of-consistent-strings/1684-count-the-number-of-consistent-strings.c b/1684-count-the-number-of-consistent-strings/1684-count-the-number-of-consistent-strings.c new file mode 100644 index 0000000..01a6ff5 --- /dev/null +++ b/1684-count-the-number-of-consistent-strings/1684-count-the-number-of-consistent-strings.c @@ -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; +} \ No newline at end of file