class Solution {
public:
int characterReplacement(string s, int k)
{
int n = s.size();
int hash[27] = {0};
int left = 0,right = 0,max = 0,ans = 0;
while(right<n)
{
int ch = s[right]-'A';
hash[ch]++;
max = max>hash[ch]?max:hash[ch];//记录窗口内出现次数最多的元素的个数
if(right-left+1-max>k)
{
ans = ans>right-left?ans:(right-left);//记录最大窗口长度
hash[s[left++]-'A']--;
}
right++;
}
ans = ans>right-left?ans:(right-left);
return ans;
}
};