# [leetcode] 334. Increasing Triplet Subsequence

Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.

Formally the function should:
Return true if there exists i, j, k
such that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false.
Your algorithm should run in O(n) time complexity and O(1) space complexity.

Examples:
Given [1, 2, 3, 4, 5],
return true.

Given [5, 4, 3, 2, 1],
return false.

class Solution {
public:
bool increasingTriplet(vector<int>& nums) {
if(nums.size() < 3)return false;
int num1 = INT_MAX;
int num2 = INT_MAX;
for(auto num:nums) {
if(num < num1)num1 = num;
else if(num > num1 && num < num2)num2 = num;
else if(num1 != INT_MAX && num2 != INT_MAX && num > num2)return true;
}
return false;
}
};

#### [leetcode] 334. Increasing Triplet Subsequence 解题报告

2016-02-19 13:14:48

#### LeetCode 300. Longest Increasing Subsequence 解题报告

2016-02-16 19:35:07

#### 【LEETCODE】300-Longest Increasing Subsequence [Python]

2016-01-07 20:36:24

#### leetcode 300. Longest Increasing Subsequence-最长子序列|动态规划

2016-06-02 20:17:05

#### leetcode（300）—— Longest Increasing Subsequence（最长递增子序列）

2016-06-08 11:33:06

#### 673. Number of Longest Increasing Subsequence 最长递增子序列的个数

2017-09-22 10:55:35

#### Leetcode 334. Increasing Triplet Subsequence

2016-02-19 06:54:27

#### Leetcode 300 Longest Increasing Subsequence（Python）

2016-07-19 01:57:14

#### [LeetCode]334. Increasing Triplet Subsequence

2016-03-17 10:22:31

#### **Leetcode 334. Increasing Triplet Subsequence

2018-03-29 23:34:09