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
Idħol biex tara l-istorja tas-sottomissjonijiet
IdħolIdħol biex tuża l-Mentor tal-AI
IdħolVisible tests
1
Input
[3,2,2,3], 3Expected
22
Input
[0,1,2,2,3,0,4,2], 2Expected
53
Input
[], 1Expected
04
Input
[1,1,1], 1Expected
05
Input
[4,5], 9Expected
26
Input
[3,2,2,3], 0Expected
4Focus radio
Paused · SomaFM · Fluid