Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 463 Bytes

2023-02-06.md

File metadata and controls

23 lines (19 loc) · 463 Bytes

题目

  1. 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
}