------
## 最终结论
```python
def number_of_nice_subarrays(nums, k):
    count = 0  # 用于存储当前窗口内的奇数计数
    result = 0  # 用于存储nice子数组的数量
    left = 0  # 左指针初始化

    for right in range(len(nums)):
        if nums[right] % 2 == 1:
            count += 1
        
        while count > k:  # 当窗口内的奇数数量大于k时，移动左指针
            if nums[left] % 2 == 1:
                count -= 1
            left += 1
        
        # 如果当前窗口内有k个奇数，则需要计算有多少个nice子数组
        if count == k:
            temp_left = left
            while temp_left < right and nums[temp_left] % 2 == 0:
                temp_left += 1
            
            temp_right = right
            while temp_right >= left and nums[temp_right] % 2 == 0:
                temp_right -= 1
            
            result += (temp_left - left + 1) * (right - temp_right + 1)

    return result
```