Simple Java solution O(n)


  • 3
    P
    public boolean increasingTriplet(int[] nums) {
        if (nums.length < 3)    return false;
        
        int min = nums[0];
        int min2 = Integer.MAX_VALUE;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > min2) {
                return true;
            } else if (nums[i] < min2 && nums[i] > min) {
                min2 = nums[i];
            } else if (nums[i] < min) {
                min = nums[i];
            }
        }
        
        return false;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.