class Solution {
public:
int thirdMax(vector<int>& nums) {
long first = LONG_MIN, sec = LONG_MIN, third = LONG_MIN;
for(int i = 0; i < nums.size(); i++) {
if (nums[i] > first) {
third = sec;
sec = first;
first = nums[i];
} else if (nums[i] > sec && nums[i] < first) {
third = sec;
sec = nums[i];
} else if (nums[i] > third && nums[i] < sec){
third = nums[i];
}
}
return (third == LONG_MIN || third == sec) ? first : third;
}
};