这个题有点坑啊。。主要是自己蠢,以为 Integer.MIN_VALUE -1 == -2147483649
public class Solution
{
public int thirdMax(int[] nums)
{
long max = (long)Integer.MIN_VALUE-1, mid = (long)Integer.MIN_VALUE-1, min = (long)Integer.MIN_VALUE-1;
for(int j: nums)
{
long i = (long)j;
if(i == max || i == min || i == mid) continue;
else if(i > max)
{
min = mid;
mid = max;
max = i;
}
else if(i > mid)
{
min = mid;
mid = i;
}
else if(i > min) min = i;
else continue;
}
if(min != (long)Integer.MIN_VALUE-1) return (int)min;
else if(max != (long)Integer.MIN_VALUE-1) return (int)max;
else return Integer.MIN_VALUE;
/*
[1,2,3,4,5]
[1,2,3,4,4,5,5]
[1,2,-2147483648]
*/
}
}