From 4fd80ba442daf1da4c93efea2bf9d1200a7fc934 Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Mon, 15 May 2023 21:19:44 -0400 Subject: [PATCH] Time: 296 ms (15.20%), Space: 18.3 MB (22.11%) - LeetHub --- ...-count-the-number-of-consistent-strings.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 1684-count-the-number-of-consistent-strings/1684-count-the-number-of-consistent-strings.py diff --git a/1684-count-the-number-of-consistent-strings/1684-count-the-number-of-consistent-strings.py b/1684-count-the-number-of-consistent-strings/1684-count-the-number-of-consistent-strings.py new file mode 100644 index 0000000..749ef05 --- /dev/null +++ b/1684-count-the-number-of-consistent-strings/1684-count-the-number-of-consistent-strings.py @@ -0,0 +1,19 @@ +class Solution: + def countConsistentStrings(self, allowed: str, words: List[str]) -> int: + allowedFilter = [False] * 26 + for c in allowed: + allowedFilter[ord(c) - ord('a')] = True + + numAllowedWords = 0 + for i in range(len(words)): + allowedWord = True + for a in words[i]: + if not allowedFilter[ord(a) - ord('a')]: + allowedWord = False + break + + if allowedWord: + numAllowedWords += 1 + + + return numAllowedWords \ No newline at end of file