Iguales al siguiente en Rust
This commit is contained in:
19
001.rs
Normal file
19
001.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
fn same_to_next(lst: &[i32]) -> Vec<i32> {
|
||||||
|
let mut _lst: Vec<i32> = Vec::new();
|
||||||
|
|
||||||
|
for idx in 0..(lst.len() - 1) {
|
||||||
|
if lst[idx] == lst[idx + 1] {
|
||||||
|
_lst.push(lst[idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _lst
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let check = vec![1, 2, 2, 2, 3, 3, 4];
|
||||||
|
println!("{:?}", same_to_next(&check)); // [2, 2, 3]
|
||||||
|
|
||||||
|
let check: Vec<i32> = (1..=10).collect();
|
||||||
|
println!("{:?}", same_to_next(&check)); // []
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user