diff --git a/1470_shuffle_the_array/Cargo.lock b/1470_shuffle_the_array/Cargo.lock new file mode 100644 index 0000000..db11e27 --- /dev/null +++ b/1470_shuffle_the_array/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "shuffle_the_array" +version = "0.1.0" diff --git a/1470_shuffle_the_array/Cargo.toml b/1470_shuffle_the_array/Cargo.toml new file mode 100644 index 0000000..3bf5844 --- /dev/null +++ b/1470_shuffle_the_array/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "shuffle_the_array" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/1470_shuffle_the_array/src/lib.rs b/1470_shuffle_the_array/src/lib.rs new file mode 100644 index 0000000..4948364 --- /dev/null +++ b/1470_shuffle_the_array/src/lib.rs @@ -0,0 +1,11 @@ +pub struct Solution; + +impl Solution { + pub fn shuffle(mut nums: Vec, _: i32) -> Vec { + let right = nums.split_off(nums.len() / 2); + nums.iter() + .zip(right) + .flat_map(|(&x, y)| vec![x, y]) + .collect() + } +}