Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit97c6349

Browse files
committed
Added Maximize the Confusion of an Exam.java
1 parent85c734a commit97c6349

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
classSolution {
2+
publicintmaxConsecutiveAnswers(StringanswerKey,intk) {
3+
intresultSize =k;
4+
Map<Character,Integer>map =newHashMap<>();
5+
for (inti =0;i <k;i++) {
6+
map.put(answerKey.charAt(i),map.getOrDefault(answerKey.charAt(i),0) +1);
7+
}
8+
intstart =0;
9+
for (inti =k;i <answerKey.length();i++) {
10+
map.put(answerKey.charAt(i),map.getOrDefault(answerKey.charAt(i),0) +1);
11+
while (Math.min(map.getOrDefault('T',0),map.getOrDefault('F',0)) >k) {
12+
map.put(answerKey.charAt(start),map.get(answerKey.charAt(start)) -1);
13+
start++;
14+
}
15+
resultSize =Math.max(resultSize,i -start +1);
16+
}
17+
returnresultSize;
18+
}
19+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp