Fourth Maximum Number
题号:NC214511
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

You are given an array of integers, return the 4th maximum number in this array. 
If it does not exist, return the maximum number. 
The time complexity must be in O(n).

输入描述:

Only 1 test case for each Input. Every test case is an non-empty array separated by " ".

输出描述:

Output the fourth maximum number of the array.
示例1

输入

复制
4 3 2 1

输出

复制
1

说明

The 4th maximum number is 1.
示例2

输入

复制
3 2 1

输出

复制
3

说明

The 4th maximum number does not exist, so return the maximum number 3.
示例3

输入

复制
4 2 2 3 1

输出

复制
1

说明

Note that the 4th maximum here means the 4th maximum distinct number. 
Both numbers with value 2 are both considered as 3rd maximum.