Skip to content

Commit a512dae

Browse files
authored
Create 2730-find-the-longest-semi-repetitive-substring.js
1 parent c186fb1 commit a512dae

File tree

1 file changed

+19
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)