-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution3095.go
39 lines (34 loc) · 960 Bytes
/
solution3095.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package solution3095
// ============================================================================
// 3095. Shortest Subarray With OR at Least K I
// URL: https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/3095---Shortest-Subarray-With-OR-at-Least-K-I
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_minimumSubarrayLength
Benchmark_minimumSubarrayLength-24 86145554 23.01 ns/op 0 B/op 0 allocs/op
PASS
*/
func minimumSubarrayLength(nums []int, k int) int {
ans := 1<<63 - 1
hasAnswer := false
for i := 0; i < len(nums); i++ {
for j := i + 1; j <= len(nums); j++ {
sum := 0
for _, v := range nums[i:j] {
sum |= v
}
if sum >= k {
ans = min(ans, len(nums[i:j]))
hasAnswer = true
}
}
}
if hasAnswer {
return ans
}
return -1
}