Skip to content

Instantly share code, notes, and snippets.

@ashleighbasil
Created April 19, 2021 03:52
Show Gist options
  • Save ashleighbasil/3c2caf786e92a9bafae1b97024be895b to your computer and use it in GitHub Desktop.
Save ashleighbasil/3c2caf786e92a9bafae1b97024be895b to your computer and use it in GitHub Desktop.
Cassidoo move zeroes solution :3
fn move_zeroes(arr: &mut Vec<i32>) -> Vec<i32> {
arr.sort_by_key(|n: &i32| n == &0);
arr.to_vec()
}
// How to use it:
fn main() {
let mut xs: Vec<i32> = vec![1, 0, 0, 5, 3, 0];
move_zeroes(&mut xs);
println!("{:?}", xs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment