30. Third Maximum Number

Find the third distinct maximum element, or return the maximum if the third does not exist.
Example 1
Input: nums = [2,2,3,1]
Output: 2
Explanation: After removing duplicates there are three distinct numbers; the third maximum is 2.
Example 2
Input: nums = [1,2]
Output: 2
Explanation: Fewer than three distinct elements — return the maximum 2.
Example 3
Input: nums = [3,2,1]
Output: 1
Explanation: Three distinct elements: the third maximum is 1.
arraysmedium
JavaScript
Loading...
Line 1, Char 1