Skip to content

Commit 8688def

Browse files
authored
Create Shortest Subarray With OR at Least K I.java
1 parent 74ecc81 commit 8688def

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int minimumSubarrayLength(int[] nums, int k) {
3+
int n = nums.length;
4+
int result = Integer.MAX_VALUE;
5+
for (int i = 0; i < n; i++) {
6+
int curr = 0;
7+
for (int j = i; j < n; j++) {
8+
curr |= nums[j];
9+
if (curr >= k) {
10+
result = Math.min(result, j - i + 1);
11+
break;
12+
}
13+
}
14+
}
15+
return result == Integer.MAX_VALUE ? -1 : result;
16+
}
17+
}

0 commit comments

Comments
 (0)