All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0301_0400.s0334_increasing_triplet_subsequence.Solution Maven / Gradle / Ivy

There is a newer version: 1.37
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy