Given an array, return the third distinct maximum number. Partial sorting or a small fixed set of tracked maxima is enough, so a full sort is unnecessary.
nums = array of integers
third distinct maximum or maximum if fewer than three distinct values exist
Example 1:
Input:
nums = [3,2,1]
Output:
1
Explanation:
The third distinct maximum is 1.
Example 2:
Input:
nums = [1,2]
Output:
2
Explanation:
Fewer than three distinct values means return the maximum.