java.lang.Object
g0901_1000.s0922_sort_array_by_parity_ii.Solution

public class Solution extends Object
922 - Sort Array By Parity II.<p>Easy</p> <p>Given an array of integers <code>nums</code>, half of the integers in <code>nums</code> are <strong>odd</strong> , and the other half are <strong>even</strong>.</p> <p>Sort the array so that whenever <code>nums[i]</code> is odd, <code>i</code> is <strong>odd</strong> , and whenever <code>nums[i]</code> is even, <code>i</code> is <strong>even</strong>.</p> <p>Return <em>any answer array that satisfies this condition</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [4,2,5,7]</p> <p><strong>Output:</strong> [4,5,2,7]</p> <p><strong>Explanation:</strong> [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [2,3]</p> <p><strong>Output:</strong> [2,3]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= nums.length <= 2 * 10<sup>4</sup></code></li> <li><code>nums.length</code> is even.</li> <li>Half of the integers in <code>nums</code> are even.</li> <li><code>0 <= nums[i] <= 1000</code></li> </ul> <p><strong>Follow Up:</strong> Could you solve it in-place?</p>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • sortArrayByParityII

      public int[] sortArrayByParityII(int[] nums)