1 2 3 4 5 6 7 8 9 10 11 12 13 14
| class Solution { public: int characterReplacement(string s, int k) { int n = s.size(), left = 0, right = 0, maxCnt = 0; vector<int> freq(26); while (right < n) { maxCnt = max(maxCnt, ++freq[s[right++] - 'A']); if (right - left > maxCnt + k) { --freq[s[left++] - 'A']; } } return right - left; } };
|