# Shouldn't [1,2,2,5,3,5] return 3 instead of 2?

• Isn't 3 the third maximum number of [1,2,2,5,3,5]? Why OJ gave 2?

• @coldknight because 5 is already the max, and can't be counted as second or third largest.

• @tgreenidge Thank you. It should say the third maximum of distinct numbers.

``````public int thirdMax(int[] nums) {
if(nums==null || nums.length==0) return 0;
long first, second, third;
first=second=third=Long.MIN_VALUE;
for(int num : nums){
if(num==first || num==second || num==third) continue;
if(num>first){
third=second;
second=first;
first=num;
}else if(num>second){
third=second;
second=num;
}else if (num>third){
third=num;
}
}
return third==Long.MIN_VALUE? (int) first: (int) third;
}``````

• Just updated the description along with examples.

• @1337c0d3r Thank you, leetcoder!

• what about [5,2,2]? the expected output is "5." There are only 2 distinct maximums and i thought it would choose "2"

• @deeTEEcee If the third maximum number does not exist, it should return the maximum number. This is clearly stated in the problem description.

• @1337c0d3r oh my mistake, i misread the problem. stupid me.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.