Evens Before Odds

Sometimes you need to split data into two groups while keeping the order inside each group. Given a list nums, return a new list where all even numbers come first, followed by all odd numbers. Keep the relative order among the even numbers and among the odd numbers.

Примеры

Ввод
[3, 1, 2, 4]
Вывод
[2, 4, 3, 1]
Ввод
[0]
Вывод
[0]
Ввод
[1, 3, 5]
Вывод
[1, 3, 5]

Нужно реализовать

def sort_array_by_parity(nums: list[int]) -> list[int]:

Теги

arraytwo-pointerssorting
PostgreSQLv16

Qui apparirà il risultato dell'esecuzione del codice

Visible tests
1
Input
[3,1,2,4]
Expected[2,4,3,1]
2
Input
[0]
Expected[0]
3
Input
[1,3,5]
Expected[1,3,5]
4
Input
[2,4,6]
Expected[2,4,6]
5
Input
[4,1,2,3]
Expected[4,2,1,3]
6
Input
[0,0,0,0]
Expected[0,0,0,0]
Focus radio
Paused · SomaFM · Fluid