[Java] PrefixSum 1pass 10line 7ms
At index i, if current odd numbers from the beginning is M,\nand we checked there was N previous index with (M - K) oddnum, then we got N subarrays\nres += N\n\
At index i, if current odd numbers from the beginning is M,\nand we checked there was N previous index with (M - K) oddnum, then we got N subarrays\nres += N\n\n\n```\n    public int numberOfSubarrays(int[] nums, int k) {\n        int cur = 0, ans = 0;\n        Map<Integer, Integer> map = new HashMap<>();\n        map.put(0, 1);\n        for (int i = 0; i < nums.length; i++) {\n            cur += nums[i] % 2 == 1 ? 1 : 0;\n            map.put(cur, map.getOrDefault(cur, 0) + 1);\n            ans += map.getOrDefault(cur - k, 0);\n        }\n        return ans;\n    }\n```\n\nArray version 7ms, faster then sliding window\n```\n    public int numberOfSubarrays(int[] nums, int k) {\n        int cur = 0, ans = 0;\n        int[] visited = new int[nums.length + 1];\n        visited[0] = 1;\n        for (int i = 0; i < nums.length; i++) {\n            cur += nums[i] % 2 == 1 ? 1 : 0;\n            visited[cur] += 1;\n            ans += cur >= k ? visited[cur - k] : 0;\n        }\n        return ans;\n    }\n```
[]