Why below solution doesn’t work for this problem?

https://leetcode.com/problems/third-maximum-number/description/

```
public int thirdMax(int[] nums) {
PriorityQueue<Integer> pq = new PriorityQueue(new Comparator<Integer>(){
public int compare(Integer a, Integer b){return b-a;}
});
int res=0;
for(int num : nums){
if(!pq.contains(num) )
pq.add(num);
}
if(pq.size()<=2){
for(int i=0; i<pq.size(); i++){
res=pq.poll();
}
}
else {
for(int i=0; i<3; i++){
res=pq.poll();
}
}
return res;
}
```

Failing test case:

Input:

[-2147483648,1,1]

Output:

-2147483648

Expected:

1

Why is the output expected as 1 when -2147483648 is the 2nd max number here?