Sliding window solution
The idea is sliding window with minor modification. Here is an example:\n2, 2, 3, 2, 2\nWe want to find 1 odd number. Using sliding window, we can find  2, 2, 1
The idea is sliding window with minor modification. Here is an example:\n```2, 2, 3, 2, 2```\nWe want to find 1 odd number. Using sliding window, we can find  `2, 2, 1`. And we delete the first two \'2\', which means that there are 3 sub-arrays that contain one 3. \n\nBut it\'s not over, there are still two 2 left in the end. Thus, for any even number afterwards, we add 3 to the final result, which means that, given an even number, we can find 3 sub-arrays. Since there are two 2, we have 2 extra 3.\n\nThus, there are in total 3 * 3 = 9 sub-arrays that contain 1 odd number. \n```\nclass Solution {\npublic:\n    int numberOfSubarrays(vector<int>& nums, int k) {\n        int i = 0, j = 0, odd_cnt = 0, tot_res = 0, tmp_res = 0;\n        for (i = 0; i < nums.size(); i++) {\n            if (nums[i] % 2 == 1) odd_cnt++;\n            while (odd_cnt == k) {\n                tmp_res++;\n                if (nums[j] % 2 == 1) odd_cnt--;\n                j++;\n            }\n            tot_res += tmp_res;\n            i++;\n            while (i < nums.size() && nums[i] % 2 == 0) {\n                tot_res += tmp_res;\n                i++;\n            }\n            i--;\n            tmp_res = 0;\n        }\n        \n        return tot_res;\n    }\n};\n```
['Sliding Window', 'C++']