Skip to main content

max_ones_index

Function max_ones_index 

Source
pub fn max_ones_index(list: &[i32]) -> Result<i32, String>
Expand description

Find the index of 0 to replace with 1 for the longest run of 1s.

Takes a list reference and returns an i32 or an error detailing the problem.

ยงExamples

Basic usage:

let result = algorithmz::array::max_ones_index(&[1,1,1,0,1,1,1,1,1,0,1,1,1]).unwrap();
assert_eq!(result,3);

Match example:

use algorithmz::array::max_ones_index;
match max_ones_index(&[1,1,1,0,1,1,1,1,1,0,1,1,1]) {
    Ok(n) => println!("The result was: {}",n),
    Err(e) => eprintln!("The problems was: {}",e),
}