Leetcode Problem 1470. Shuffle the Array

1470. Shuffle the Array

Leetcode Solutions

Approach: Simple Iteration

  1. Initialize an empty array result of size 2 * n.
  2. Loop through the indices from 0 to n - 1:
    • At each index i, place nums[i] at result[2 * i] (even index).
    • Place nums[i + n] at result[2 * i + 1] (odd index).
  3. Return the result array.
UML Thumbnail

Approach: In-place Filling

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...