Sort Array By Parity

Given an integer array `nums`, reorder the array in-place so that all even integers appear before odd integers. You can return any valid reordering.

Input Format

nums = array of integers

Output Format

array reordered so evens come before odds (in-place or return array)

Constraints

Examples

Example 1:

Input:

nums = [3,1,2,4]

Output:

[2,4,1,3]

Explanation:

One valid answer is [2,4,3,1] where all even numbers (2,4) precede odd ones.

Example 2:

Input:

nums = [0]

Output:

[0]

Explanation:

Single element array remains [0].

Loading...
Sort Array By Parity - Two Pointers DSA Problem