3295. Report Spam Message
You are given an array of strings message and an array of strings bannedWords.
An array of words is considered spam if there are at least two words in it that exactly match any word in bannedWords.
Return true if the array message is spam, and false otherwise.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| class Solution { public: bool reportSpam(vector<string>& message, vector<string>& bannedWords) { unordered_set<string> b(begin(bannedWords), end(bannedWords)); int cnt = 0; for(auto& m : message) { if(b.count(m)) { if(++cnt >= 2) break; } } return cnt >= 2; } };
|