Solution was accepted. Found one case where it fails.


  • 3
    M

    My solution is the following:

    public class Solution {
    
        public boolean increasingTriplet(int[] nums) {
            int len = nums.length;
            int i = 0, min = Integer.MAX_VALUE, min2 = Integer.MAX_VALUE;
        
            if(len < 3){
                return false;
            }
        
            while(i < len-1){
                if(nums[i] < min) min = nums[i];
                if(nums[i+1] > min2) return true;
                if(nums[i] < nums[i+1]){
                    if(nums[i+1] < min2) min2 = nums[i+1];
                    if(nums[i] > min) return true;
                }
                i++;
            }
            return false;
        }
    }
    

    The case where it fails is when the input is: [5,1,5,5,2,1,4]. So maybe add more test cases to this problem?


  • 0
    J

    Your idea is nice,just modify a bit: to iterate through array--nums, find minimum giving the min, and next minimum to the min2 ,when nums[i]>min2 return true.


  • 0
    J

    yes, the problem's Editorial answer also has defect, it cannot decide equal cases, also like this case [1, 5, 5]


Log in to reply
 

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