Runner-Up Value

Sometimes the maximum is not enough, and you need the next unique value after it. Given a list nums, return the second largest distinct number. Repeated copies of the same value do not count as different candidates. If there is no second distinct value, return None.

Примеры

Ввод
[3, 1, 4, 1, 5, 9, 2, 6]
Вывод
6
Ввод
[5, 5, 5]
Вывод
None
Ввод
[2, 1]
Вывод
1

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

def second_largest(nums: list[int]) -> int | None:

Теги

array
PostgreSQLv16

Taispeánfar toradh do chóid anseo

Visible tests
1
Input
[3,1,4,1,5,9,2,6]
Expected6
2
Input
[5,5,5]
ExpectedNone
3
Input
[2,1]
Expected1
4
Input
[10]
ExpectedNone
5
Input
[1,2,2,2]
Expected1
6
Input
[-1,-2,-3]
Expected-2
Focus radio
Paused · SomaFM · Fluid