leetcode 3095. 或值至少 K 的最短子数组 I
题目:3095. 或值至少 K 的最短子数组 I - 力扣(LeetCode)
加班用手机刷水题
class Solution {
public:
int minimumSubarrayLength(vector<int>& nums, int k) {
int n = nums.size();
int m, l, ret = n + 10;
for (int i = 0; i < n; i++) {
m = 0;
l = 0;
for (int j = i; j < n; j++) {
++l;
m |= nums[j];
if (m >= k) {
if (l < ret) {
ret = l;
if (ret == 1) {
return 1;
}
}
break;
}
}
}
if (ret > n) {
return -1;
}
return ret;
}
};