- Shuffle the Array
Given the array nums
consisting of 2n
elements in the form [x1,x2,...,xn,y1,y2,...,yn]
.
Return the array in the form [x1,y1,x2,y2,...,xn,yn]
.
// runtime 82.22% memory 87.82%
var shuffle = function(nums, n) {
const res = []
for (let i = 0; i < n; i++) {
res[i * 2] = nums[i]
}
for (let i = n; i < n * 2; i++) {
res[(i - n) * 2 + 1] = nums[i]
}
return res
}