feat: 1470_shuffle_the_array

This commit is contained in:
SquidSpirit 2025-08-20 02:22:04 +08:00
parent 30a13831b7
commit 47e2090304
3 changed files with 24 additions and 0 deletions

7
1470_shuffle_the_array/Cargo.lock generated Normal file
View File

@ -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"

View File

@ -0,0 +1,6 @@
[package]
name = "shuffle_the_array"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@ -0,0 +1,11 @@
pub struct Solution;
impl Solution {
pub fn shuffle(mut nums: Vec<i32>, _: i32) -> Vec<i32> {
let right = nums.split_off(nums.len() / 2);
nums.iter()
.zip(right)
.flat_map(|(&x, y)| vec![x, y])
.collect()
}
}