← 返回 citadel 的题目列表Second Largest Distinct Value
类型:online_judge
Problem
Implement second_largest_unique(nums): given a list of integers, return the second-largest distinct value.
Return None if fewer than two distinct values exist.
The input may contain duplicates and negative integers.
Examples:
[3, 1, 4, 4, 5, 5, 2] -> 4
[7, 7, 7] -> None
[-1, -2] -> -2
Input Format
First line: integer n
Second line: n space-separated integers; it may be empty when n = 0
Output Format
Print the second-largest distinct value, or None if it does not exist.
Constraints
0 <= n <= 200000
-10^9 <= nums[i] <= 10^9
Example
Input:
7
3 1 4 4 5 5 2
Output:
4
Example
Input
0
Output
None