2024/10/24 灵茶题单 不定长滑动窗口
This commit is contained in:
parent
d97230a73b
commit
db30196d08
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue