Count a Value
You often need to know how many times a specific value appears in a list, such as how many orders have a certain status. Write a function count_occurrences that goes through nums and counts how many elements are equal to target. If the list is empty or the value is not found, return 0.
Примеры
Ввод
[1, 2, 2, 3, 2], 2Вывод
3Ввод
[1, 2, 3], 4Вывод
0Ввод
[], 1Вывод
0Нужно реализовать
def count_occurrences(nums: list[int], target: int) -> int:
Теги
arraylists
Pieslēdzies, lai redzētu iesniegumu vēsturi
PieslēgtiesPieslēdzies, lai izmantotu AI mentoru
PieslēgtiesTests12
Visible tests
Slēptais tests 7
Slēptais tests 8
Slēptais tests 9
Slēptais tests 10
Slēptais tests 11
Slēptais tests 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid