C++ Solution


  • 0
    K
    class Solution {
    public:
    	int thirdMax(vector<int>& nums) {
    		sort(nums.begin(), nums.end(), greater<int>());
    		int size = nums.size();
    		int count = 0;
    		int i = 0, j=i+1;
    		while (j<size && count<2)
    		{
    			if (nums[i] != nums[j]) {
    				count++;
    			}
    			i++;
    			j++;
    		}
    		if (count == 2) return nums[i];
    		else return nums[0];
    
    
    	}
    
    };
    

Log in to reply
 

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