题意:
给你一个由不同字符组成的字符串 allowed 和一个字符串数组 words 。
如果一个字符串的每一个字符都在 allowed 中,就称这个字符串是 一致字符串 。
请你返回 words 数组中 一致字符串 的数目。
数据范围:
1 <= words.length <= 1e4
1 <= allowed.length <= 26
1 <= words[i].length <= 10
allowed 中的字符 互不相同 。
words[i] 和 allowed 只包含小写英文字母。
解法:
用map标记串allowed中的字符,
然后对于words中的每个串,判断是否所有字符都被标记了即可.
code:
class Solution {
public:
int countConsistentStrings(string s, vector<string>& a) {
map<char,int>mp;
for(auto i:s)mp[i]=1;
int ans=0;
for(auto i:a){
int ok=1;
for(auto j:i){
if(!mp[j]){
ok=0;
}
}
ans+=ok;
}
return ans;
}
};