LeetCode 1470. Shuffle the Array (javascript solution)
codingpineapple
Posted on June 6, 2021
Description:
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].
Solution:
Time Complexity : O(n)
Space Complexity: O(n)
var shuffle = function(nums, n) {
let res = []
for(let i = 0; i < n; i++){
res.push(nums[i], nums[i+n])
}
return res
};
π πͺ π
π©
codingpineapple
Posted on June 6, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
sorting Recap the highlight of the sorting algorithms using JavaScript for beginners
October 5, 2024
datastructures DSA with JS: Understanding Custom Array Data Structure in JavaScript - A Step-by-Step Guide
September 29, 2024