334. Increasing Triplet Subsequence
Input: [1,2,3,4,5]
Output: trueInput: [5,4,3,2,1]
Output: falsebool increasingTriplet(vector<int>& nums) { // time: O(n); space: O(1)
int c1 = INT_MAX, c2 = INT_MAX;
for (int num : nums) {
if (num <= c1) c1 = num;
else if (num <= c2) c2 = num;
else return true;
}
return false;
}Last updated