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

Commit53cdf2d

Browse files
add 2024
1 parent37d4e34 commit53cdf2d

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ _If you like this project, please leave me a star._ ★
1010
|-----|----------------|---------------|--------|-------------|-------------
1111
|2028|[Find Missing Observations](https://leetcode.com/problems/find-missing-observations/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2028.java)||Medium||
1212
|2027|[Minimum Moves to Convert String](https://leetcode.com/problems/minimum-moves-to-convert-string/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2027.java)||Easy||
13+
|2024|[Maximize the Confusion of an Exam](https://leetcode.com/problems/maximize-the-confusion-of-an-exam/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2024.java)||Medium||
1314
|2023|[Number of Pairs of Strings With Concatenation Equal to Target](https://leetcode.com/problems/number-of-pairs-of-strings-with-concatenation-equal-to-target/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2023.java)||Medium||
1415
|2022|[Convert 1D Array Into 2D Array](https://leetcode.com/problems/convert-1d-array-into-2d-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2022.java)||Easy||
1516
|2018|[Check if Word Can Be Placed In Crossword](https://leetcode.com/problems/check-if-word-can-be-placed-in-crossword/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2018.java)||Medium||
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_2024 {
4+
publicstaticclassSolution1 {
5+
publicintmaxConsecutiveAnswers(StringanswerKey,intk) {
6+
intmax;
7+
//change T to F and count number of Fs
8+
intright =0;
9+
intoriginalK =k;
10+
while (k >0 &&right <answerKey.length()) {
11+
if (answerKey.charAt(right) =='T') {
12+
k--;
13+
}
14+
right++;
15+
}
16+
max =right;
17+
intleft =0;
18+
while (right <answerKey.length() &&left <answerKey.length()) {
19+
if (answerKey.charAt(right) =='F') {
20+
right++;
21+
max =Math.max(max,right -left);
22+
}else {
23+
while (left <right &&answerKey.charAt(left) =='F') {
24+
left++;
25+
}
26+
left++;
27+
right++;
28+
}
29+
}
30+
31+
//change F to T
32+
right =0;
33+
k =originalK;
34+
while (k >0 &&right <answerKey.length()) {
35+
if (answerKey.charAt(right) =='F') {
36+
k--;
37+
}
38+
right++;
39+
}
40+
max =Math.max(max,right);
41+
left =0;
42+
while (right <answerKey.length() &&left <answerKey.length()) {
43+
if (answerKey.charAt(right) =='T') {
44+
right++;
45+
max =Math.max(max,right -left);
46+
}else {
47+
while (left <right &&answerKey.charAt(left) =='T') {
48+
left++;
49+
}
50+
left++;
51+
right++;
52+
}
53+
}
54+
returnmax;
55+
}
56+
}
57+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._2024;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_2024Test {
10+
privatestatic_2024.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_2024.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(4,solution1.maxConsecutiveAnswers("TTFF",2));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(3,solution1.maxConsecutiveAnswers("TFFT",1));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals(5,solution1.maxConsecutiveAnswers("TTFTTFTT",1));
30+
}
31+
32+
@Test
33+
publicvoidtest4() {
34+
assertEquals(1,solution1.maxConsecutiveAnswers("F",1));
35+
}
36+
37+
@Test
38+
publicvoidtest5() {
39+
assertEquals(8,solution1.maxConsecutiveAnswers("FFFTTFTTFT",3));
40+
}
41+
42+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp