diff --git a/src/Python/001.py b/src/Python/001.py new file mode 100644 index 0000000..23e1b5e --- /dev/null +++ b/src/Python/001.py @@ -0,0 +1,16 @@ +# def same_to_next(lst: list) -> list: +# same_to_next_lst = [] +# for idx, element in enumerate(lst[:-1]): +# if lst[idx] == lst[idx+1]: +# same_to_next_lst.append(element) +# return same_to_next_lst + +def same_to_next(lst: list) -> list: + return [x for x, y in zip(lst, lst[1:]) if x == y] + + +check = [1, 2, 2, 2, 3, 3, 4] +print(same_to_next(check)) # [2, 2, 3] + +check = list(range(1, 11)) +print(same_to_next(check)) # [] diff --git a/src/Rust/001 b/src/Rust/001 new file mode 100755 index 0000000..7b27e68 Binary files /dev/null and b/src/Rust/001 differ diff --git a/src/Rust/001.rs b/src/Rust/001.rs new file mode 100644 index 0000000..493d369 --- /dev/null +++ b/src/Rust/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