Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

public int thirdMax(int[] nums) { Arrays.sort(nums); int n=1; for(int i=nums.length-2;i>=0;i--){ if(nums[i]!=nums[i+1]) n++; if(n==3) return nums[i]; } return nums[nums.length-1]; }

but your solution is not O(n),since you sort your array,the time complexity should be O(nlogn)

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