---
# System prepended metadata

title: 1470. Shuffle the Array
tags: [Leetcode]

---

<style>
    html, body, .ui-content {
    background: #222222;
    color: #00BFFF;
}
    /* 設定 code 模板 */
    .markdown-body code,
.markdown-body tt {
    background-color: #ffffff36;
}
.markdown-body .highlight pre,
.markdown-body pre {
    color: #ddd;
    background-color: #00000036;
}
.hljs-tag {
    color: #ddd;
}
.token.operator {
  background-color: transparent;
}    
/* 設定連結 */
a,
.open-files-container li.selected a {
    color: #89FFF8;
    
}
a:hover,
.open-files-container li.selected a:hover {
    color: #89FFF890;
}
   
</style>

###### tags: `Leetcode`

# 1470. Shuffle the Array

###### Link : https://leetcode.com/problems/shuffle-the-array/description/

## 題目

[x1,x2,...,xn,y1,y2,...,yn] 
-> 
[x1,y1,x2,y2,...,xn,yn]

## 程式碼
```cpp=
class Solution {
public:
    vector<int> shuffle(vector<int>& nums, int n){
        vector<int> ans(2 * n);
        for(int i = 0, j = n;i < n;i++, j++){
            ans[i * 2] = nums[i];
            ans[i * 2 + 1] = nums[j];
        }
        return ans;
    }
};
```

## Date 
### 2023/2/6