Zeros to the End
Zeros often represent empty or less important values, so it can be useful to move them behind the real data. Given a list of integers nums, return a new list where all non-zero elements keep their original order. Move all zeros to the end.
Примеры
Ввод
[0, 1, 0, 3, 12]Вывод
[1, 3, 12, 0, 0]Ввод
[0, 0, 0]Вывод
[0, 0, 0]Ввод
[1, 2, 3]Вывод
[1, 2, 3]Нужно реализовать
def move_zeros(nums: list[int]) -> list[int]:
Теги
arraytwo-pointers
Entre para ver seu histórico de envios
EntrarEntre para usar o AI Mentor
EntrarVisible tests
1
Input
[0,1,0,3,12]Expected
[1,3,12,0,0]2
Input
[0,0,0]Expected
[0,0,0]3
Input
[1,2,3]Expected
[1,2,3]4
Input
[]Expected
[]5
Input
[0]Expected
[0]6
Input
[4,0,5,0,0,6]Expected
[4,5,6,0,0,0]Focus radio
Paused · SomaFM · Fluid