How Many Unique Values

When a list contains repeats, you often need to know how many different values are actually there. The function count_distinct receives a list of numbers nums and returns the number of distinct elements. If the list is empty, it has 0 distinct values.

Примеры

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

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

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

Теги

listsset
PostgreSQLv16

Tutaj pojawi się wynik wykonania kodu

Visible tests
1
Input
[1,2,2,3]
Expected3
2
Input
[]
Expected0
3
Input
[5,5,5]
Expected1
4
Input
[1,2,3,4]
Expected4
5
Input
[7,7,8,8,9]
Expected3
6
Input
[7]
Expected1
Focus radio
Paused · SomaFM · Fluid