Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int characterReplacement(string s, int k) {
- int maxLen = 0, windowStart = 0, maxRepeatLetterCount = 0;
- unordered_map<char,int> charFreq;
- for(int windowEnd = 0; windowEnd<s.size(); windowEnd++){
- char rightChar = s[windowEnd];
- charFreq[rightChar]++;
- maxRepeatLetterCount = max(maxRepeatLetterCount,charFreq[rightChar]);
- if(windowEnd - windowStart + 1 - maxRepeatLetterCount > k){
- char leftChar = s[windowStart];
- charFreq[leftChar]--;
- windowStart++;
- }
- maxLen = max(maxLen,windowEnd-windowStart+1);
- }
- return maxLen;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment