Sharing my 8ms C++ solution


  • 0
    T
    class Solution {
    public:
        bool increasingTriplet(vector<int>& nums) {
            int i, n = nums.size();
            if(n<3)
                return false;
            
            int minimum = nums[0];
            int secondMinimum = INT_MIN;
            for(i=1; i<n; i++)
            {
                if(nums[i]<=minimum)
                    minimum = nums[i];
                else if(secondMinimum==INT_MIN || secondMinimum>=nums[i])
                    secondMinimum = nums[i];
                else 
                    return true;
            }
            
            return false;
        }
    };

Log in to reply
 

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