```
public class Solution {
public int thirdMax(int[] nums) {
Arrays.sort(nums);
int j=0;
int maxnum =0;
for (int i=nums.length-1; i>=1; i--) {
maxnum = Math.max(maxnum,nums[i]);
if(nums[i-1] != nums[i]) {
j++;
}
if (j==2) return nums[i-1];
}
return maxnum;
}
}
```