-
Notifications
You must be signed in to change notification settings - Fork 0
/
awkward.js
38 lines (31 loc) · 869 Bytes
/
awkward.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* @param {string} s
* @return {number}
*/
var minimumLength = function(s) {
while(s.length > 0){
if(s.length == 1 || s[0] != s[s.length-1]){
break;
}
let character = s[0];
let prefixIndex = 1;
for(;prefixIndex < s.length; ++prefixIndex){
if(character != s[prefixIndex]){
break;
}
}
//console.log(s);
s = s.slice(prefixIndex, s.length);
//console.log(`${' '.repeat(prefixIndex)}`+s);
let suffixIndex = s.length-2;
for(;suffixIndex>0;--suffixIndex){
if(character!=s[suffixIndex]){
break;
}
}
//console.log(s);
s = s.slice(0, suffixIndex+1);
//console.log(s);
}
return s.length;
};