Skip to content

Commit 92cf1f6

Browse files
authored
Create 1876-substrings-of-size-three-with-distinct-characters.js
1 parent b4aa0b3 commit 92cf1f6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const countGoodSubstrings = function(s) {
6+
let res = 0
7+
for(let i = 2; i < s.length; i++) {
8+
if(chk(s, i)) res++
9+
}
10+
11+
return res
12+
};
13+
14+
function chk(s, i) {
15+
return s[i - 2] !== s[i - 1] &&
16+
s[i - 2] !== s[i] &&
17+
s[i - 1] !== s[i]
18+
}

0 commit comments

Comments
 (0)