Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int numberOfSubarrays(vector<int>& nums, int k) {
- int ans, left, right, count;
- ans = left = right = count = 0;
- int sz = nums.size();
- int fans = 0;
- for(right=0; right<sz; right++){
- if(nums[right] & 1) count++, ans=0;
- while(count == k){
- ans++;
- if(nums[left++] & 1) count--;
- }
- fans += ans;
- }
- return fans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement