Class Solution

java.lang.Object
g1401_1500.s1470_shuffle_the_array.Solution

public class Solution extends Object
1470 - Shuffle the Array.<p>Easy</p> <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>,&hellip;,x<sub>n</sub>,y<sub>1</sub>,y<sub>2</sub>,&hellip;,y<sub>n</sub>]</code>.</p> <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>,&hellip;,x<sub>n</sub>,y<sub>n</sub>]</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [2,5,1,3,4,7], n = 3</p> <p><strong>Output:</strong> [2,3,5,4,1,7]</p> <p><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].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,2,3,4,4,3,2,1], n = 4</p> <p><strong>Output:</strong> [1,4,2,3,3,2,4,1]</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [1,1,2,2], n = 2</p> <p><strong>Output:</strong> [1,2,1,2]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 500</code></li> <li><code>nums.length == 2n</code></li> <li><code>1 <= nums[i] <= 10^3</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • shuffle

      public int[] shuffle(int[] nums, int n)