Remove a Value

When cleaning a list, you often need to remove every item with one specific value, such as cancelled statuses or zero markers. Given a list nums and a value val, remove all occurrences of val. Return the number of elements that remain after removal.

Примеры

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

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

def remove_element(nums: list[int], val: int) -> int:

Теги

arraytwo-pointers
PostgreSQLv16

Ovdje će se prikazati rezultat izvršavanja koda

Visible tests
1
Input
[3,2,2,3], 3
Expected2
2
Input
[0,1,2,2,3,0,4,2], 2
Expected5
3
Input
[], 1
Expected0
4
Input
[1,1,1], 1
Expected0
5
Input
[4,5], 9
Expected2
6
Input
[3,2,2,3], 0
Expected4
Focus radio
Paused · SomaFM · Fluid