思路:记录两个值,一个small,一个big。遍历数组,如果小于small,则更新small,不然如果小于big,则更新big,如果大于big,则存在递增三元子序列
bool increasingTriplet(vector<int>& nums) {
int small = INT32_MAX;
int big = INT32_MAX;
int i = 0;
while (i < nums.size()) {
if (nums[i] <= small)
small = nums[i];
else if (nums[i] > small && nums[i] <= big)
big = nums[i];
else
return true;
i++;
}
return false;
}