From b19737570c79a8f1af3d195b7f62f3bd9c1866c7 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Fri, 8 May 2026 16:55:44 +0200 Subject: [PATCH] Iguales al siguiente en Rust --- 001.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 001.rs diff --git a/001.rs b/001.rs new file mode 100644 index 0000000..493d369 --- /dev/null +++ b/001.rs @@ -0,0 +1,19 @@ +fn same_to_next(lst: &[i32]) -> Vec { + let mut _lst: Vec = 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 = (1..=10).collect(); + println!("{:?}", same_to_next(&check)); // [] +} \ No newline at end of file