```
public class Solution {
public int thirdMax(int[] nums) {
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
for (int i : nums) {
if (!pq.contains(i)) {
pq.add(i);
}
if (pq.size() > 3) {
pq.poll();
}
}
if (pq.size() == 2) {
pq.poll();
}
return pq.poll();
}
}
```