// 要求时间复杂度为O(n),所以不能进行排序
int thirdMax(vector<int>& nums) {
if (nums.size() == 0) return -1;
long one = LONG_MIN;// 这么写的原因是因为int的最小值INT_MIN,如果将one写成 int one = INT_MIN
// ,那么如果nums里面第三个数是INT_MIN,检测不出来
long two = LONG_MIN;
long three = LONG_MIN;
if (nums.size() == 2) return nums[0] > nums[1] ? nums[0] : nums[1];
for (int i = 0; i < nums.size(); i++) {
if (nums[i] > one) {
three = two;
two = one;
one = nums[i];
}
else if (nums[i] > two&&nums[i] < one) {
three = two;
two = nums[i];
}
else if (nums[i] > three&& nums[i] < two)
three = nums[i];
}
// 后面两个相同,前面两相同,三个相同
if (three == LONG_MIN) return (int)one;
if (one == three || one == two || two == three)
return one;
return (int)three;
}