JAVA | Sliding Window
\nclass Solution {\n    public int numberOfSubarrays(int[] nums, int k) {\n        int oddcount=0;\n        int res=0;\n        int i=0;\n        int count=0;\n
```\nclass Solution {\n    public int numberOfSubarrays(int[] nums, int k) {\n        int oddcount=0;\n        int res=0;\n        int i=0;\n        int count=0;\n        for(int j=0;j<nums.length;j++){\n            if(nums[j]%2==1){\n                oddcount++;\n                count=0;\n            }\n            while(oddcount==k){\n                if(nums[i++]%2==1) oddcount--;\n                count++;\n            }\n            res+=count;\n        }\n        return res;\n    }\n}\n```
[]