C++ O(n) solution


  • 1
    J
    bool increasingTriplet(vector<int>& nums) {
        int min1 = INT_MAX, min2 = INT_MAX;
        for(int i = 1; i<nums.size(); i++) {
            if(nums[i-1] < nums[i]) {
                if(min2 < nums[i] || min1 < nums[i-1]) 
                    return true;
                
                min1 = nums[i-1];
                min2 = nums[i];
            }
            
            min1 = min(nums[i], min1);
        }
        
        return false;
    }

  • 0
    C

    Brilliant.You can comment this line:
    //min1 = min(nums[i], min1);


Log in to reply
 

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