Solved LeetCode program · 902 of 1,000
#1248 · Count Number of Nice Subarrays
Original English source
The readings is a list of 1, 1, 2, 1, and 1. The wanted is 3. The seen is a list of 6 zeros. Set item 0 of seen to 1. The odds is 0. The ways is 0.
For each value in readings.
If value modulo 2 is 1, add 1 to odds. If odds is at least wanted, The prior is item (odds minus wanted) of seen, Set ways to ways plus prior. Increase item odds of seen by 1.
Show ways.
Expected stdout
2