```
int thirdMax(vector<int>& nums)
{
sort(nums.begin(),nums.end());
int n=nums.size();
int temp=nums[n-1];
for(int i=n-1, count=1;i>=0;i--)
{
if(nums[i]!=temp)
{
count++;
temp=nums[i];
}
if(count==3)
return temp;
}
return nums[n-1];
}
```