Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
407 B
5
Indexable
Never
class Solution {
public:
    int characterReplacement(string s, int k) {
        vector<int>f(26, 0);
        int mxCnt = 0, mxLen = 0;
        for(int l=0, r=0; r<(int)s.length(); ++r){
            mxCnt = max(mxCnt, ++f[s[r]-'A']);
            if(r-l+1-mxCnt > k){
                --f[s[l++]-'A'];
            }
            mxLen = max(mxLen, r-l+1);
        }
        return mxLen;
    }
};
Leave a Comment