Leetcode编程c++之1684. 统计一致字符串的数目
给你一个由不同字符组成的字符串 allowed 和一个字符串数组 words 。如果一个字符串的每一个字符都在 allowed 中,就称这个字符串是 一致字符串 。
请你返回 words 数组中 一致字符串 的数目。
class Solution {
public:
bool cmp(string t, string s){
for(int i=0;i<s.size();i++){
bool f=true;
for(int j=0; j<t.size();j++){
if(s[i] == t[j]){
f = false;
break;
}
}
if(f)
return false;
}
return true;
}
int countConsistentStrings(string allowed, vector<string>& words) {
int count = 0;
for(auto&word : words)
if(cmp(allowed, word))
count++;
return count;
}
};