Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
565 B
3
Indexable
Never
class Solution {
public:
    int countConsistentStrings(string allowed, vector<string>& words) {
        unordered_map < int, bool > seen;
        
        int ans = 0;
        
        for(int i=0;i<allowed.size();i++) {
            seen[allowed[i] - 'a'] = true;
        }
        
        for(int i=0;i<words.size();i++) {
            int cnt = 0, sz = words[i].size();
            for(int j=0;j<sz;j++) {
                if(seen[words[i][j] - 'a'])cnt++;
            }
            
            if(sz == cnt)ans++;
        }
        
        return ans;
    }
};
Leave a Comment