1684.统计一致字符串的数目
链接:1684.统计一致字符串的数目
难度:Easy
标签:位运算、数组、哈希表、字符串
简介:请你返回 words 数组中 一致字符串 的数目。
题解 1 - cpp
- 编辑时间:2022-11-08
- 执行用时:32ms
- 内存消耗:29.4MB
- 编程语言:cpp
- 解法介绍:遍历。
class Solution {
public:
    int countConsistentStrings(string allowed, vector<string>& words) {
        int list[26] = {0};
        for (auto &c : allowed) list[c - 'a'] = 1;
        int ans = 0;
        for (auto &s : words) {
            bool f = true;
            for (auto &c : s) {
                if (list[c - 'a'] == 0) {
                    f = false;
                    break;
                }
            }
            if (f) ans++;
        }
        return ans;
    }
};