Sort Array by Parity
Requirements:
Given an integer array nums
, move all the even integers at
the beginning of the array followed by all the odd integers. The values
should be in increasing order.
Example 1:
Input: words = [1, 2, 3, 4, 5, 6]
Output: [2, 4, 6, 1, 2, 3]
There are three even values and three odd values, already in increasing
order. We should move [2,4,6]
to the front, followed
by [1,2,3]
.
Example 2:
Input: nums = [0]
Output: [0]
The algorithm shouldn't break in this case of only one even value and no odd values, returning the same as the input.
Example 3:
Input: nums = [2, 6, 4, 6, 4, 2]
Output: [2, 2, 4, 4, 6, 6]
There are six even values and no odd values. The algorithm should sort the array.
nums:
Please try and complete this project before viewing the solution.