Simple Java HashMap Solution O(n) by keeping track of count of odd numbers
```\nclass Solution {\n    public int numberOfSubarrays(int[] nums, int k) {\n        \n        int n = nums.length;\n        \n        HashMap map = new HashMa
```\nclass Solution {\n    public int numberOfSubarrays(int[] nums, int k) {\n        \n        int n = nums.length;\n        \n        HashMap<Integer, Integer> map = new HashMap<>();\n        \n        int ans = 0;\n        int currCount = 0;\n        \n        map.put(0, 1);\n        \n        for(int i = 0; i < n; i++){\n            if(nums[i] % 2 == 1) currCount ++;\n            if(map.containsKey(currCount - k)) ans += map.get(currCount - k);\n            if(!map.containsKey(currCount)) map.put(currCount, 1);\n            else map.put(currCount, 1 + map.get(currCount));\n        }\n        \n        return ans;\n        \n    }\n}
[]