class Solution {

public int minimumLength(String s) {

int i = 0;

int j = s.length()-1;

while(i < j && s.charAt(i) == s.charAt(j)){

char c = s.charAt(i);

while(i<=j && s.charAt(i) == c){

i++;

}

while(i<=j && s.charAt(j) == c){

j–;

}

}

return j-i+1;

}

}

class Solution {

public:

int minimumLength(string s) {

int i = 0;

int j = s.length() – 1;

while (i < j && s[i] == s[j]) {

char c = s[i];

while (i <= j && s[i] == c)

++i;

while (i <= j && s[j] == c)

–j;

}

return j – i + 1;

}

};

class Solution:

def minimumLength(self, s: str) -> int:

i = 0

j = len(s) – 1

while i < j and s[i] == s[j]:

c = s[i]

while i <= j and s[i] == c:

i += 1

while i <= j and s[j] == c:

j -= 1

return j – i + 1