Skip to content

Commit 80f303b

Browse files
solve #3095: Shortest Subarray With OR at Least K I
in java
1 parent e4e5920 commit 80f303b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@
900900
| 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers) | [![Java](assets/java.png)](src/FindTheSumOfEncryptedIntegers.java) | |
901901
| 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse) | [![Java](assets/java.png)](src/ExistenceOfASubstringInAStringAndItsReverse.java) | |
902902
| 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences) | [![Java](assets/java.png)](src/MaximumLengthSubstringWithTwoOccurrences.java) | |
903-
| 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | | |
903+
| 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i) | [![Java](assets/java.png)](src/ShortestSubarrayWithORAtLeastKI.java) | |
904904
| 3099 | [Harshad Number](https://leetcode.com/problems/harshad-number) | | |
905905
| 3105 | [Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray) | | |
906906
| 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string) | | |

Diff for: src/ShortestSubarrayWithORAtLeastKI.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i
2+
// T: O(N^2)
3+
// S: O(1)
4+
5+
public class ShortestSubarrayWithORAtLeastKI {
6+
public int minimumSubarrayLength(int[] array, int k) {
7+
int minLength = Integer.MAX_VALUE;
8+
for (int i = 0 ; i < array.length ; i++) {
9+
int current = array[i];
10+
for (int j = i ; j < array.length ; j++) {
11+
current |= array[j];
12+
if (current >= k) {
13+
minLength = Math.min(minLength, j - i + 1);
14+
}
15+
}
16+
}
17+
return minLength == Integer.MAX_VALUE ? -1 : minLength;
18+
}
19+
}

0 commit comments

Comments
 (0)