Leetcode 414 Third Maximum Number
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
int thirdMax(vector<int>& nums) {
sort(nums.begin(), nums.end());
int sign = 0;
for (int i = nums.size() - 1; i > 0; i--){
if (nums[i] != nums[i - 1]){
sign++;
if (sign == 2)
return nums[i - 1];
}
}
return nums[nums.size() - 1];
}
};