Leetcode 334 Solution

This article provides solution to leetcode question 334 (increasing-triplet-subsequence)

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

Solution

class Solution {
public:
    bool increasingTriplet(vector<int>& nums) {
        set<int> s;

        for (auto num : nums)
        {
            auto it = s.lower_bound(num);
            if (it != s.end())
                s.erase(it);
            s.insert(num);

            if (s.size() >= 3)
                return true;
        }

        return false;
    }
};