[LeetCode]#1684. Count the Number of Consistent Strings

Input: allowed = "ab", words = ["ad","bd","aaab","baa","badab"]
Output: 2
Explanation: Strings "aaab" and "baa" are consistent since they only contain characters 'a' and 'b'.

Analysis:

  1. if find not allowed letter, constant n=n+1
  2. all word number -n =answer
class Solution:
def countConsistentStrings(self, allowed, words):

not_match=0
for word in words:
for w in word:
if w not in allowed:
not_match+=1
break
ans=len(words)-not_match
return ans

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store