Easy c++ using vector


  • 0
    X
    int thirdMax(vector<int>& nums) 
        {
            sort(nums.begin(),nums.end());
            int n=nums.size();
            int temp=nums[n-1];
            for(int i=n-1, count=1;i>=0;i--)
            {
                if(nums[i]!=temp)
                {
                    count++;
                    temp=nums[i];
                }
                if(count==3)
                    return temp;
            }
            return nums[n-1]; 
        }
    

Log in to reply
 

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