Second Largest Value
EasyArraySorting
Description
Given an array of integers nums containing at least two distinct values, return the second largest distinct value.
Examples
Input:
nums = [3,1,4,1,5]Output:
4Explanation:
After the maximum, the next distinct value down the list is 4.
Input:
nums = [10,10,9]Output:
9Explanation:
After the maximum, the next distinct value down the list is 9.
Input:
nums = [-1,-2,-3]Output:
-2Explanation:
After the maximum, the next distinct value down the list is -2.
Constraints
- •
2 ≤ nums.length ≤ 10⁴ - •
At least two distinct values exist.