Solved LeetCode program · 768 of 1,000
#1004 · Max Consecutive Ones III
Original English source
Keep a shared bits as an empty list of whole numbers. Keep a shared limit of 0. Keep a shared opening of 0. Keep a shared zeros of 0. Keep a shared best of 0.
To shrink from spot (a whole number).
Repeat while zeros is more than limit.
If item spot of bits is 0, subtract 1 from zeros. Add 1 to spot. Set opening to spot.
Set limit to 2. Place 1 into bits. Place 1 into bits. Place 1 into bits. Place 0 into bits. Place 0 into bits. Place 0 into bits. Place 1 into bits. Place 1 into bits. Place 1 into bits. Place 1 into bits. Place 0 into bits.
For every right from 0 to the last position of bits.
If item right of bits is 0, add 1 to zeros. Shrink from opening. The width is right minus opening plus 1. If width is more than best, set best to width.
Show best.
Expected stdout
6