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
Work Hard
But do not forget to enjoy life😀
本文来自博客园,作者:YuhangLiuCE,转载请注明原文链接:https://www.cnblogs.com/YuhangLiuCE/p/17084281.html