Another O(n) algorithm focused on inflection point with python


  • 0
    E
    def increasingTriplet(self, nums):
        if len(nums)<3:return False
        a,b=None,None
        for i in range(1,len(nums)):
            if nums[i]<=nums[i-1]:continue #find inflection point
            if a is None or b is None:a,b=nums[i-1],nums[i]
            else:
                if nums[i]>b or nums[i-1]>a:return True
                a,b=nums[i-1],nums[i]
        return False
    

Log in to reply
 

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