跳至主要内容

1684. Count the Number of Consistent Strings

· 閱讀時間約 1 分鐘

Hint

class Solution {
public:
int countConsistentStrings(string allowed, vector<string>& words)
{
unordered_set<int> st(allowed.begin(), allowed.end());
int cnt = words.size();
for (auto word : words)
{
for (auto w : word)
{
if (!st.count(w))
{
cnt--;
break;
}
}
}
return cnt;
}
};
  • T: $O(m + n \cdot k)$
  • S: $O(m)$