Java 1ms Solution


  • 0
    C
    public boolean increasingTriplet(int[] a) {
            int p=-1;
            int c=1;
            int start=0;
            int prev_p=Integer.MAX_VALUE;
            for(int i=1;i<a.length;i++){
                if(prev_p!=Integer.MAX_VALUE && a[prev_p]<a[i])
                    return true;
                if(a[i]>a[i-1] && c==1){
                    start=i-1;
                    p=i;
                    c++;
                }
                else{
                    if(c==1)
                        continue;
                    else{
                        if(a[i]>a[start] && a[i]>a[p])
                            return true;
                        else{
                            if(a[i]<a[p] && a[i]>a[start])
                                p=i;
                            else{
                                if(a[i]<a[start]){
                                    prev_p=p;
                                    start=i;
                                    c=1;
                                }
                            }    
                        }
                    }
                }
            }
            return false;
        }

Log in to reply
 

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