```
public class Solution {
public int thirdMax(int[] nums) {
int a = Integer.MIN_VALUE;
int b = Integer.MIN_VALUE;
int c = Integer.MIN_VALUE;
for (int num : nums) {
if (num > a) {
c = b;
b = a;
a = num;
}
else if (num > b && num != a) {
c = b;
b = num;
}
else if (num > c && num != a && num != b) {
c = num;
}
}
return nums.length < 3 ? a : c;
}
}
```