diff --git a/cpp/2203/220329-CN.cpp b/cpp/2203/220329-CN.cpp new file mode 100644 index 0000000..86faab6 --- /dev/null +++ b/cpp/2203/220329-CN.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +class Solution { +public: + static int maxConsecutiveAnswers(const std::string& answerKey, int k) { + int n = answerKey.length(); + std::function solve = [&](char ch) { + int L = 0, R = 0, cnt = 0; + // Interval: [L, R) + // Initial + for (; R < n && cnt < k; ++R) + if (answerKey[R] != ch) + ++cnt; + int ret = R - L; + for (; R < n; ++R) { + if (answerKey[R] != ch) { + ret = std::max(ret, R - L); + while (answerKey[L] == ch) + ++L; + ++L; + } + } + return std::max(ret, R - L); + }; + return std::max(solve('T'), solve('F')); + } +}; + +int main() { + std::cout << Solution::maxConsecutiveAnswers("TFFT", 1); + return 0; +} diff --git a/cpp/2203/CMakeLists.txt b/cpp/2203/CMakeLists.txt index ba66ab5..71d7eb1 100644 --- a/cpp/2203/CMakeLists.txt +++ b/cpp/2203/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2203) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2203 220329.cpp) +ADD_EXECUTABLE(2203 220329-CN.cpp)