Skip to content

Commit 37c9697

Browse files
add 3095
1 parent bad04e7 commit 37c9697

File tree

3 files changed

+50
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src

3 files changed

+50
-0
lines changed

Diff for: paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
| 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3127.java) | | Easy |
3030
| 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3120.java) | | Easy |
3131
| 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3110.java) | | Easy |
32+
| 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3095.java) | | Easy |
3233
| 3062 | [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3062.java) | | Easy |
3334
| 3046 | [Split the Array](https://leetcode.com/problems/split-the-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3046.java) | | Easy |
3435
| 3042 | [Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3042.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3095 {
4+
public static class Solution1 {
5+
public int minimumSubarrayLength(int[] nums, int k) {
6+
int min = Integer.MAX_VALUE;
7+
for (int i = 0; i < nums.length; i++) {
8+
if (nums[i] >= k) {
9+
return 1;
10+
}
11+
int or = nums[i];
12+
for (int j = i + 1; j < nums.length; j++) {
13+
or |= nums[j];
14+
if (or >= k) {
15+
min = Math.min(min, j - i + 1);
16+
}
17+
}
18+
}
19+
return min == Integer.MAX_VALUE ? -1 : min;
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.fourththousand;
2+
3+
import com.fishercoder.solutions.fourththousand._3095;
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 _3095Test {
10+
private static _3095.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _3095.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(3, solution1.minimumSubarrayLength(new int[]{2, 1, 8}, 10));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(-1, solution1.minimumSubarrayLength(new int[]{1, 12, 2, 5}, 43));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)