C++ | Leetcode C++题解之第424题替换后的最长重复字符
题目:
题解:
class Solution {
public:int characterReplacement(string s, int k) {vector<int> num(26);int n = s.length();int maxn = 0;int left = 0, right = 0;while (right < n) {num[s[right] - 'A']++;maxn = max(maxn, num[s[right] - 'A']);if (right - left + 1 - maxn > k) {num[s[left] - 'A']--;left++;}right++;}return right - left;}
};