Skip to content

Commit

Permalink
Create: 1470-shuffle-the-array
Browse files Browse the repository at this point in the history
  • Loading branch information
AkifhanIlgaz committed Feb 6, 2023
1 parent ee7a3bc commit 07e1146
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions rust/1470-shuffle-the-array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
impl Solution {
pub fn shuffle(nums: Vec<i32>, n: i32) -> Vec<i32> {
let mut nums = nums;

for i in 0..n as usize {
nums[i] = nums[i] << 10;
nums[i] = nums[i] | nums[i + n as usize];
}

let mut j = 2 * n - 1;

for i in (0..=n as usize - 1).rev() {
let y = nums[i] & (2_i32.pow(10) - 1);
let x = nums[i] >> 10;
nums[j as usize] = y;
nums[j as usize - 1] = x;
j -= 2;
}

nums
}
}

0 comments on commit 07e1146

Please sign in to comment.