#905

Sort Array By Parity

newbie · 210 · lc easy +16 · verified · 76.5% accepted · 5,677 likes · top 88%

Description

Given an integer array nums, reorder its elements so every even number precedes every odd number. Any arrangement satisfying this constraint is acceptable.

Example 1:

Input: nums = [3,1,2,4]
Output: [2,4,3,1]
Explanation: The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.

Example 2:

Input: nums = [0]
Output: [0]

Code

1
2
3