2019-11-10 LeetCode in Rust LeetCode 487. Max Consecutive Ones II Problem Statement impl Solution { pub fn find_max_consecutive_ones(a: Vec<i32>) -> i32 { let (mut ans, mut zeros, mut sum) = (0, 0, 0); let mut i = 0; for j in 0..a.len() { if a[j] == 0 { zeros += 1; } while zeros > 1 { if a[i] == 0 { zeros -= 1; } i += 1; } ans = std::cmp::max(ans, j - i + 1); } return ans as i32; }} Newer LeetCode 485. Max Consecutive Ones Older LeetCode 494. Target Sum