From db30196d087e656fbefabec6382d0fe1ae99a555 Mon Sep 17 00:00:00 2001 From: Cool <747682928@qq.com> Date: Thu, 24 Oct 2024 12:20:26 +0800 Subject: [PATCH] =?UTF-8?q?2024/10/24=20=E7=81=B5=E8=8C=B6=E9=A2=98?= =?UTF-8?q?=E5=8D=95=20=E4=B8=8D=E5=AE=9A=E9=95=BF=E6=BB=91=E5=8A=A8?= =?UTF-8?q?=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sliding_windows/Num2024.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/com/cool/ling_cha_mount/sliding_windows/Num2024.java diff --git a/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num2024.java b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num2024.java new file mode 100644 index 0000000..41788fe --- /dev/null +++ b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num2024.java @@ -0,0 +1,29 @@ +package com.cool.ling_cha_mount.sliding_windows; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/10/24/12:20 + * @Description: 2024. 考试的最大困扰度 + * @Score 1643 + */ +public class Num2024 { + public int maxConsecutiveAnswers(String answerKey, int k) { + int res = 0; + int tNum = 0; + int left = 0; + for (int i = 0; i < answerKey.length(); i++) { + if (answerKey.charAt(i) == 'T') { + tNum++; + } + while (tNum > k && tNum < i - left + 1 - k) { + if (answerKey.charAt(left++) == 'T') { + tNum--; + } + } + res = Math.max(res, i - left + 1); + } + return res; + } +}