Skip to content

Commit d121bba

Browse files
authored
Create 3295-report-spam-message.js
1 parent 0e865b8 commit d121bba

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

3295-report-spam-message.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {string[]} message
3+
* @param {string[]} bannedWords
4+
* @return {boolean}
5+
*/
6+
var reportSpam = function(message, bannedWords) {
7+
let res = false
8+
const m = message.length, n = bannedWords.length
9+
let cnt = 0
10+
const bs = new Set(bannedWords)
11+
for(let i = 0; i < m; i++) {
12+
const str = message[i]
13+
/*
14+
for(let j = 0; j < n; j++) {
15+
const e = bannedWords[j]
16+
if(str === e) {
17+
cnt++
18+
break
19+
}
20+
}
21+
*/
22+
if(bs.has(str)) cnt++
23+
if(cnt >= 2) return true
24+
}
25+
26+
return res
27+
};

0 commit comments

Comments
 (0)