Increasing Triplet Subsequence

https://leetcode.com/problems/increasing-triplet-subsequence/

class Solution {
public:
    bool increasingTriplet(vector<int>& nums) {
        int n = nums.size();
        if(n < 3)
        {
            return false;
        }

        vector<int> vec(3, INT_MAX);

        for(int i : nums)
        {
            if(i <= vec[0])
            {
                vec[0] = i;
            }
            else if(i <= vec[1])
            {
                vec[1] = i;
            }
            else
            {
                return true;
            }
        }

        return false;
    }
};

results matching ""

    No results matching ""