class Solution {
public:
int characterReplacement(string s, int k) {
int N = s.length();
int mp[30];
memset(mp,0,sizeof(mp));
int ans = 0;
int L = 0;
for(int R=0;R<N;R++){
mp[s[R]-'A'] ++ ;
for(;L<=R;L++){
int mx = 0;
for(int i=0;i<26;i++) mx = max(mx,mp[i]);
if(R-L+1-mx<=k){
ans = max(ans,R-L+1);
break;
}else mp[s[L]-'A'] -- ;
}
}
return ans;
}
};
No.97 - LeetCode424 - 替换K个字符最大重复子串 - 统计字符滑动窗口
最新推荐文章于 2022-07-02 10:40:13 发布