I'm trying to see how many numbers are bigger than the previous number in a vector. This is my code so far:
fn get_result(depths: &Vec<u32>) {
let mut result: Vec<u32> = Vec::new();
for (idx,num) in depths.iter().enumerate() {
if depths[idx - 1] > depths[idx] {
result.push(depths[idx]);
}
}
println!("{:?}", result);
}
When I run this, it gives me the following error:
thread main panicked at 'attempt to subtract with overflow'
I know that this is caused by the depths[idx - 1], but I'm not entirely sure how to keep track of the previous index.