Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).
1
Example 1:
2
Input: [3, 2, 1]
3
4
Output: 1
5
6
Explanation: The third maximum is 1.
7
Example 2:
8
Input: [1, 2]
9
10
Output: 2
11
12
Explanation: The third maximum does not exist, so the maximum (2) is returned instead.
13
Example 3:
14
Input: [2, 2, 3, 1]
15
16
Output: 1
17
18
Explanation: Note that the third maximum here means the third maximum distinct number.
19
Both numbers with value 2 are both considered as second maximum.