Zeroes to the End

Sometimes you need to move zeroes out of the main part of a list while keeping the other values in order. Given nums, return a list where all non-zero elements keep their original relative order. All zeroes should be placed at the end. Do not reorder the non-zero values among themselves.

Примеры

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

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

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

Теги

arraytwo-pointers
PostgreSQLv16

Tu sa zobrazí výsledok spustenia kódu

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