1684. Count the Number of Consistent Strings
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 88% Topics: Array, Hash Table, String, Bit Manipulation, Counting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def countConsistentStrings(self, allowed, words):
"""
:type allowed: str
:type words: List[str]
:rtype: int
"""
lookup = [False]*26
for c in allowed:
lookup[ord(c)-ord('a')] = True
result = len(words)
for word in words:
for c in word:
if not lookup[ord(c)-ord('a')]:
result -= 1
break
return result
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions