334. Increasing Triplet Subsequence
Input: [1,2,3,4,5]
Output: trueInput: [5,4,3,2,1]
Output: falseclass Solution {
public boolean increasingTriplet(int[] nums) {
if(nums == null || nums.length == 0) return false;
int m1 = Integer.MAX_VALUE, m2 = Integer.MAX_VALUE;
for(int i : nums){
if(m1 >= i) m1 = i;
else if(m2 >= i) m2 = i;
else return true;
}
return false;
}
}Last updated