leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2024.cpp (471B)
0 class Solution { 1 public: 2 int maxConsecutiveAnswers(string answerKey, int k) { 3 int i = 0, j = 0, res = 0, t = 0, f = 0; 4 while (true) { 5 if (min(t, f) <= k) { 6 if (j == answerKey.size()) break; 7 (answerKey[j++] == 'T' ? t : f)++; 8 } else { 9 res = max(res, j - i); 10 (answerKey[i++] == 'T' ? t : f)--; 11 } 12 } 13 return max(res - 1, j - i); 14 } 15 };