|
| 1 | +<h2><a href="https://leetcode.com/problems/shuffle-the-array">1580. Shuffle the Array</a></h2><h3>Easy</h3><hr><p>Given the array <code>nums</code> consisting of <code>2n</code> elements in the form <code>[x<sub>1</sub>,x<sub>2</sub>,...,x<sub>n</sub>,y<sub>1</sub>,y<sub>2</sub>,...,y<sub>n</sub>]</code>.</p> |
| 2 | + |
| 3 | +<p><em>Return the array in the form</em> <code>[x<sub>1</sub>,y<sub>1</sub>,x<sub>2</sub>,y<sub>2</sub>,...,x<sub>n</sub>,y<sub>n</sub>]</code>.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> nums = [2,5,1,3,4,7], n = 3 |
| 10 | +<strong>Output:</strong> [2,3,5,4,1,7] |
| 11 | +<strong>Explanation:</strong> Since x<sub>1</sub>=2, x<sub>2</sub>=5, x<sub>3</sub>=1, y<sub>1</sub>=3, y<sub>2</sub>=4, y<sub>3</sub>=7 then the answer is [2,3,5,4,1,7]. |
| 12 | +</pre> |
| 13 | + |
| 14 | +<p><strong class="example">Example 2:</strong></p> |
| 15 | + |
| 16 | +<pre> |
| 17 | +<strong>Input:</strong> nums = [1,2,3,4,4,3,2,1], n = 4 |
| 18 | +<strong>Output:</strong> [1,4,2,3,3,2,4,1] |
| 19 | +</pre> |
| 20 | + |
| 21 | +<p><strong class="example">Example 3:</strong></p> |
| 22 | + |
| 23 | +<pre> |
| 24 | +<strong>Input:</strong> nums = [1,1,2,2], n = 2 |
| 25 | +<strong>Output:</strong> [1,2,1,2] |
| 26 | +</pre> |
| 27 | + |
| 28 | +<p> </p> |
| 29 | +<p><strong>Constraints:</strong></p> |
| 30 | + |
| 31 | +<ul> |
| 32 | + <li><code>1 <= n <= 500</code></li> |
| 33 | + <li><code>nums.length == 2n</code></li> |
| 34 | + <li><code>1 <= nums[i] <= 10^3</code></li> |
| 35 | +</ul> |
0 commit comments