Files
leetcode/1684-count-the-number-of-consistent-strings/1684-count-the-number-of-consistent-strings.py
T

19 lines
600 B
Python

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