首页 > 其他分享 >1684

1684

时间:2023-02-01 22:12:36浏览次数:32  
标签:ac cc flag 1684 words allowed 字符串

给你一个由不同字符组成的字符串 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

 

标签:ac,cc,flag,1684,words,allowed,字符串
From: https://www.cnblogs.com/LYoungH/p/17084281.html

相关文章

  • CF1684F Diverse Segments
    本题的问题等价于删除一个区间之后是否询问的所有区间都没有相同的数对。记录\(i\)的\(minL_i\)表示包含\(i\)的区间的最小左端点\(maxR_i\)同理,每次删除\(i\)......
  • leetcode-1684-easy
    CounttheNumberofConsistentStringsYouaregivenastringallowedconsistingofdistinctcharactersandanarrayofstringswords.Astringisconsistenti......
  • Leetcode第1684题:统计一致字符串的数目(Count the number of consistent strings)
    解题思路采用位运算的思路不太好理解。但思想就是根据allowed建立一个\(mask\),遍历words中的每个元素的每个字符c,查看\(mask\)的值是否为真。如果存在就返回结果加一。......
  • 1684. 统计一致字符串的数目
    1684.统计一致字符串的数目给你一个由不同字符组成的字符串 allowed 和一个字符串数组 words 。如果一个字符串的每一个字符都在allowed 中,就称这个字符串是一致......