C++ Solution by using 32bit integers


  • 0
    Z

    int thirdMax(vector<int>& nums) {

        int a = INT_MIN;
        int b = INT_MIN;
        int c = INT_MIN;
        int min = INT_MAX;
        
        for(auto n: nums) {
            if(n > a) {
                c = b;
                b = a;
                a = n;
            } else if(n > b && n < a) {
                c = b ;
                b = n;
            } else if(n > c && n < b) {
                c = n;
            } 
            
            if(n < min)
                min = n;
       }
      
      return (min <= c && b > c)? c: a;   
    

    }


Log in to reply
 

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