返回顶部

1684

给你一个由不同字符组成的字符串 allowed 和一个字符串数组 words 。如果一个字符串的每一个字符都在 allowed 中,就称这个字符串是 一致字符串 

请你返回 words 数组中 一致字符串 的数目。

输入:allowed = "cad", words = ["cc","acd","b","ba","bac","bad","ac","d"]
输出:4
解释:字符串 "cc","acd","ac" 和 "d" 是一致字符串。
class Solution(object):
    def countConsistentStrings(self, allowed, words):
        """
        :type allowed: str
        :type words: List[str]
        :rtype: int
        """
        flag=1
        n=0
        for word in words:
            flag=1
            for char in word:
                if char not in allowed:
                    flag=0
            if(flag==1):
                n=n+1
        return n

 

posted @ 2023-02-01 22:00  YuhangLiuCE  阅读(177)  评论(0编辑  收藏  举报