Skip to content

Commit 84724a5

Browse files
authored
Create 1316-distinct-echo-substrings.js
1 parent 51c68ea commit 84724a5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

1316-distinct-echo-substrings.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {string} text
3+
* @return {number}
4+
*/
5+
const distinctEchoSubstrings = function (text) {
6+
const set = new Set()
7+
for(let len = 1; len <= text.length / 2; len++) {
8+
for(let l = 0, r = len, count = 0; l < text.length - len; l++, r++) {
9+
if(text.charAt(l) === text.charAt(r)) count++
10+
else count = 0
11+
12+
if(count === len) {
13+
set.add(text.slice(l - len + 1, l + 1))
14+
count--
15+
}
16+
}
17+
}
18+
return set.size
19+
}

0 commit comments

Comments
 (0)