```
class Solution {
public:
int characterReplacement(string s, int k) {
if(s.empty()) return 0;
int res = INT_MIN;
for(int cnt = 0; cnt < 26; ++cnt){
char curChar = 'A' + cnt;
int i = 0, j = 0, r = k;
while(j < s.size()){
while(j < s.size()){
if(s[j] != curChar){
if(r == 0) break;
else{r--;}
}
j++;
}
res = max(res, j - i);
while(s[i] == curChar){i++;}
++i;//skip to the next non-curChar position.
r++;
}
}
return res;
}
};
```