python力扣刷题记录——1684. 统计一致字符串的数目

题目:

给你一个由不同字符组成的字符串 allowed 和一个字符串数组 words 。如果一个字符串的每一个字符都在 allowed
中,就称这个字符串是 一致字符串 。 请你返回 words 数组中 一致字符串
的数目。在这里插入图片描述

方法:
执行用时: 76 ms
内存消耗: 15.9 MB

class Solution:
    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:
        count = 0
        for i in words:
            for j in i:
                if j not in allowed:
                    count += 1
                    break
        count_all = len(words) - count
        return count_all

猜你喜欢

转载自blog.csdn.net/weixin_45455015/article/details/111244318