Java Solution, Beats 100.00%
Intuition\nThe problem requires us to find the number of continuous subarrays that contain exactly k odd numbers. The approach used in the given code leverages 
# Intuition\nThe problem requires us to find the number of continuous subarrays that contain exactly `k` odd numbers. The approach used in the given code leverages prefix sums and a hashmap to efficiently count the number of valid subarrays.\n\n# Approach\n1. **Prefix Sum with HashMap**: The idea is to use a prefix sum array where each element in the prefix sum represents the count of odd numbers up to the current index in the `nums` array.\n   \n2. **Counting Prefix Sums**: A hashmap (implemented as an array `cnt` in the code) is used to keep track of the number of times each prefix sum has occurred.\n\n3. **Traversing the Array**: As we traverse through the `nums` array:\n   - We maintain a running count `t` of the number of odd numbers encountered so far.\n   - For each element, we check if there is a prefix sum that is exactly `k` less than the current prefix sum (`t - k`). If it exists, it means there is a subarray ending at the current index that contains exactly `k` odd numbers.\n   - We update our result `ans` by adding the count of such prefix sums found in the hashmap.\n   - We then update the hashmap to include the current prefix sum.\n\n# Complexity\n- **Time Complexity**: The code runs in `O(n)` time, where `n` is the length of the input array `nums`. This is because we traverse the array once, and all operations inside the loop (including hashmap operations) are `O(1)` on average.\n  \n- **Space Complexity**: The space complexity is `O(n)` due to the hashmap (`cnt` array) used to store the count of prefix sums. In the worst case, we might have to store up to `n+1` different prefix sums.\n\n# Detailed Steps in Code\n1. Initialize the hashmap `cnt` with `n+1` size (to handle cases where prefix sums go up to `n`) and set `cnt[0] = 1` because a prefix sum of zero has occurred once before starting.\n2. Traverse through the array and for each element:\n   - Update the running total `t` to count odd numbers.\n   - Check if `(t - k)` is a valid prefix sum. If so, add the count of this prefix sum to `ans`.\n   - Update the hashmap with the current prefix sum.\n\n# Code\n```java\nclass Solution {\n    public int numberOfSubarrays(int[] nums, int k) {\n        int n = nums.length;\n        int[] cnt = new int[n + 1]; // HashMap to store prefix sums\n        cnt[0] = 1; // Base case: prefix sum of 0 occurs once\n        int ans = 0, t = 0; // ans: result, t: current prefix sum (count of odd numbers)\n        \n        for (int v : nums) {\n            t += v & 1; // Increment prefix sum if the number is odd\n            if (t - k >= 0) {\n                ans += cnt[t - k]; // If (t - k) exists in cnt, add its count to ans\n            }\n            cnt[t]++; // Increment the count of current prefix sum in cnt\n        }\n        \n        return ans; // Return the total number of valid subarrays\n    }\n}\n```
['Java']