### Increasing Triplet Subsequence

Total Accepted: 14818 Total Submissions: 43443 Difficulty: Medium

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.

Credits:
Special thanks to @DjangoUnchained for adding this problem and creating all test cases.

Subscribe to see which companies asked this question

java code:

public class Solution {
public boolean increasingTriplet(int[] nums) {

int max = (1<<31)-1;
int mid = (1<<31)-1;

for(int num : nums) {
if(num <= mid)
mid = num;
else if(num <= max)
max = num;
else
return true;
}

return false;
}
}

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

2016-02-19 13:14:48

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

2016-02-17 11:39:42

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

2016-02-16 19:35:07

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

2016-06-02 20:17:05

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

2016-01-07 20:36:24

#### Increasing Triplet Subsequence

2016-02-17 01:28:31

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

2016-06-08 11:33:06

#### [LeetCode] Increasing Triplet Subsequence

2016-02-16 21:39:32

#### Leetcode Increasing Triplet Subsequence

2016-04-24 18:02:52

#### LWC 49：674. Longest Continuous Increasing Subsequence

2017-09-10 14:03:50

## 不良信息举报

LeetCode:Increasing Triplet Subsequence