```
class Solution {
public:
int thirdMax(vector<int>& v) {
long long *arr = new long long[3];
fill_n(arr, 3, numeric_limits<long long>::min());
for(auto i : v) {
if(i == arr[0] || i == arr[1] || i == arr[2])
continue;
if(i > arr[0]) {
arr[2] = arr[1];
arr[1] = arr[0];
arr[0] = i;
}
else if(i > arr[1]) {
arr[2] = arr[1];
arr[1] = i;
}
else if(i > arr[2])
arr[2] = i;
}
return arr[2] == numeric_limits<long long>::min() ? arr[0] : arr[2];
}
};
```