mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 18:07:32 +01:00
21 lines
341 B
Java
21 lines
341 B
Java
|
class Solution {
|
||
|
public int minimumLength(String s) {
|
||
|
int i = 0;
|
||
|
int j = s.length() - 1;
|
||
|
|
||
|
while (i < j && s.charAt(i) == s.charAt(j)) {
|
||
|
var c = s.charAt(i);
|
||
|
|
||
|
while (i <= j && s.charAt(i) == c) {
|
||
|
++i;
|
||
|
}
|
||
|
|
||
|
while (j > i && s.charAt(j) == c) {
|
||
|
--j;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return j - i + 1;
|
||
|
}
|
||
|
}
|