```
public class Solution {
public int thirdMax(int[] nums) {
int max, mid, min;
max = mid = min = Integer.MIN_VALUE;
for(int i=0; i<nums.length; i++){
if(nums[i]>max){
min = mid;
mid = max;
max = nums[i];
}else if(nums[i]>mid&&nums[i]!=max){
min = mid;
mid = nums[i];
}else if(nums[i]>min&&nums[i]!=mid){
min = nums[i];
}
}
return min == Integer.MIN_VALUE? max:min;
}
}
```

It returns right answer when input is [3,2,1],

but it returns 5, when input is [1,2,2,5,3,5].