JavaScript solution


  • 0
    S
    var thirdMax = function(nums) {
        nums = Array.from(new Set(nums));
        var len = nums.length;
        if(len<=2){
        	return Math.max(...nums);
        }
        if(len===3){
        	return Math.min(...nums);
        }
        nums = nums.sort((a,b)=>{return b-a;})
        return nums[2];
    };
    

Log in to reply
 

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