力扣2024.考试的最大困扰度
力扣2024.考试的最大困扰度
-
注意同时>k才处理
-
class Solution {public:int maxConsecutiveAnswers(string answerKey, int k) {int n = answerKey.size(),res=0;unordered_map<int,int> cnt;for(int i=0,j=0;i<n;i++){cnt[answerKey[i] - 'a'] ++;while(cnt['T' - 'a'] > k && cnt['F' - 'a'] > k){cnt[answerKey[j] - 'a'] --;j++;}res = max(res,i-j+1);}return res;}};