1684. Count the Number of Consistent Strings

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1684

class Solution:
    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:
        def f(w):
            return reduce(or_, (1 << (ord(c) - ord('a')) for c in w))

        mask = f(allowed)
        return sum((mask | f(w)) == mask for w in words)