g0301_0400.s0334_increasing_triplet_subsequence.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
package g0301_0400.s0334_increasing_triplet_subsequence;
// #Medium #Top_Interview_Questions #Array #Greedy
public class Solution {
public boolean increasingTriplet(int[] nums) {
int n = nums.length;
int i = 0;
int low = Integer.MAX_VALUE;
int high = Integer.MAX_VALUE;
while (i < n) {
if (low >= nums[i]) {
low = nums[i++];
} else if (high >= nums[i]) {
high = nums[i++];
} else {
return true;
}
}
return false;
}
}