use std::cmp::Ordering; fn main() { let a = find_intersections([ String::from("-2, -1, 1, 1, 1, 2, 3, 6"), String::from("-1, 1, 1, 3, 4, 5, 6") ]); println!("{}", a); } fn find_intersections(arr: [String; 2]) -> String { let mut inter : Vec<isize> = Vec::new(); let mut a = arr[0].split(",").map( |e| e.trim().parse::<isize>().unwrap() ); let mut b = arr[1].split(",").map( |e| e.trim().parse::<isize>().unwrap() ); let mut tmp_a = a.next(); let mut tmp_b = b.next(); while tmp_a.is_some() && tmp_b.is_some() { match tmp_a.unwrap().partial_cmp(&tmp_b.unwrap()).expect("NAN is evil") { Ordering::Less => tmp_a = a.next(), Ordering::Equal => {inter.push(tmp_a.unwrap()); tmp_a = a.next();tmp_b = b.next()}, Ordering::Greater => tmp_b = b.next(), } } if inter.is_empty() { return String::from("false") } return inter.into_iter().map(|x| x.to_string()).collect::<Vec<String>>().join(", ") }
A rust solution, im quite new to rust, so this is probably quite ugly
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A rust solution, im quite new to rust, so this is probably quite ugly