nikunjsoni

1248

Apr 9th, 2021
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int numberOfSubarrays(vector<int>& nums, int k) {
  4.         int ans, left, right, count;
  5.         ans = left = right = count = 0;
  6.         int sz = nums.size();
  7.         int fans = 0;
  8.        for(right=0; right<sz; right++){
  9.            if(nums[right] & 1) count++, ans=0;
  10.            while(count == k){
  11.                ans++;
  12.                if(nums[left++] & 1) count--;
  13.            }
  14.            fans += ans;
  15.        }
  16.        return fans;
  17.     }
  18. };
RAW Paste Data