leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

3097.cpp (800B)


0 class Solution {
1 inline static int update(int count[32], int num, int value) {
2 int crnt = 0;
4 for (int k = 0; k < 32; k++) {
5 const auto bit = 1 << k;
6 if (num & bit) count[k] += value;
7 if (count[k]) crnt |= bit;
8 }
10 return crnt;
11 }
13 public:
14 int minimumSubarrayLength(const vector<int> &nums, int k) const {
15 static int count[32];
16 unsigned res = -1;
18 memset(count, 0x00, sizeof(count));
19 for (int i = 0, j = 0; j < size(nums); j++) {
20 int crnt = update(count, nums[j], 1);
22 for (; i <= j && crnt >= k; i++) {
23 res = min(res, (unsigned)(j - i + 1));
24 crnt = update(count, nums[i], -1);
25 }
26 }
28 return res;
29 }
30 };