mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-09 04:09:20 +00:00
feat: add array3.rs exercise
This commit is contained in:
parent
340aa0ad5c
commit
393816f393
31
exercises/array/array3.rs
Normal file
31
exercises/array/array3.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// array3.rs
|
||||
//
|
||||
// Here is the code for how the array learns
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
|
||||
|
||||
struct soultion;
|
||||
|
||||
impl soultion{
|
||||
pub fn move_zero(nums:&mut Vec<i32>){
|
||||
let mut i=0;
|
||||
for j in 0..nums.len(){
|
||||
if nums[j] !=0{
|
||||
nums[i] = nums[j];
|
||||
i+=1;
|
||||
}
|
||||
}
|
||||
// for loop through
|
||||
for k in i ..nums.len(){
|
||||
nums[k] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut v = vec![1,23,0,0,0,3,4,5];
|
||||
soultion::move_zero( &mut v);
|
||||
println!("v:{:?}",v);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user