Skip to content

Commit ac4d7f2

Browse files
authored
Create 1750-minimum-length-of-string-after-deleting-similar-ends.js
1 parent 4c2cf58 commit ac4d7f2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const minimumLength = function(s) {
6+
const n = s.length
7+
let l = 0, r = n - 1
8+
while(l < r && s[l] === s[r]) {
9+
while(l < r - 1 && s[r] === s[r - 1]) r--
10+
while(l + 1 < r && s[l] === s[l + 1]) l++
11+
l++
12+
r--
13+
}
14+
return r - l + 1
15+
};

0 commit comments

Comments
 (0)