---
# System prepended metadata

title: Leetcode 1470. Shuffle the Array
tags: [daily, leetcode]

---

# Leetcode 1470. Shuffle the Array
###### tags: `leetcode` `daily`

[題目連結](https://leetcode.com/problems/shuffle-the-array/description/)

# Method simulation
:::info
:bulb: **作法講解**:
scan array nums from i is from 0 ~ n-1,
for each index i, put nums[i] into output and put nums[i+n] into output.
:::

TC: O(N) SC: O(N)
:::spoiler 完整程式碼
```cpp=
class Solution {
public:
    vector<int> shuffle(vector<int>& nums, int n) {
        vector<int> output(n * 2, 0);
        int idx = 0;

        for(int i = 0 ; i < n ; i++) {
            output[idx++] = nums[i];
            output[idx++] = nums[i+n];
        }
        return output;
    }
};
```
:::


