LeetCode – Increasing Triplet Subsequence (Java)
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.
Examples:
Given [1, 2, 3, 4, 5],
return true.
Given [5, 4, 3, 2, 1],
return false.
Analysis
This problem can be formalized as finding a sequence x, y and z, such that x < y < z .
Java Solution
public boolean increasingTriplet(int[] nums) { int small = Integer.MAX_VALUE; int big = Integer.MAX_VALUE; for (int num: nums) { if (num <= small) { small = num;// update x to be a smaller value } else if (num <= big) { big = num; // update y to be a smaller value } else { return true; } } return false; } 
<pre><code> String foo = "bar"; </code></pre>

IntoTheMystic

algohack

algohack

Bonsai

Bonsai

alexwest11

afj

ryanlr

ryanlr

ryanlr

Samir Vasani

kash

Ashiq Imran

Ankit Shah

Ankit Shah