Posted on

Description

Submission

class Solution {
public:
    int minimumLength(string s) {
        int l = s.length();
        int i = 0, j = l - 1;
        for(; i < j; ++i, --j) {
            char cur = s[i];
            if(s[j] != cur) break;
            while(j-1 > i && s[j-1] == cur) --j;
            while(i+1 < j && s[i+1] == cur) ++i;
        }
        
        return j - i + 1;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *