Skip to content

Commit 1458f2d

Browse files
add 2511
1 parent 0c547ba commit 1458f2d

File tree

3 files changed

+44
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+44
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2525.java) | [:tv:](https://youtu.be/dIciftyQXHo) | Easy ||
4646
| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2520.java) | [:tv:](https://youtu.be/7SHHsS5kPJ8) | Easy ||
4747
| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2515.java) || Easy ||
48+
| 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2511.java) || Easy |Array, Two Pointers
4849
| 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2506.java) || Easy ||
4950
| 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2500.java) || Easy ||
5051
| 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2496.java) || Easy ||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
public class _2511 {
4+
public static class Solution1 {
5+
public int captureForts(int[] forts) {
6+
int max = 0;
7+
for (int i = 0; i < forts.length; i++) {
8+
if (forts[i] == 1 || forts[i] == -1) {
9+
for (int j = i + 1; j < forts.length; j++) {
10+
if ((forts[i] == 1 && forts[j] == -1) || (forts[i] == -1 && forts[j] == 1)) {
11+
max = Math.max(max, j - i - 1);
12+
break;
13+
} else if ((forts[j] == 1 && forts[i] == 1) || forts[j] == -1 && forts[i] == -1) {
14+
break;
15+
}
16+
}
17+
}
18+
}
19+
return max;
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2511;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _2511Test {
10+
private static _2511.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2511.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(4, solution1.captureForts(new int[]{1, 0, 0, -1, 0, 0, 0, 0, 1}));
20+
}
21+
}

0 commit comments

Comments
 (0)