Third Maximum Number
Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number.
Follow up: Can you find an O(n) solution?
Example 1
Input
nums = [3,2,1]Output
1The first, second, and third distinct maximums are 3, 2, and 1, respectively.
Example 2
Input
nums = [1,2]Output
2The third distinct maximum does not exist, so the maximum value 2 is returned instead.
Constraints
- 1 <= nums.length <= 10^4
- -2^31 <= nums[i] <= 2^31 - 1