Python O(n) solution


  • 0
    B
    class Solution(object):
        def increasingTriplet(self, nums):
            """
            :type nums: List[int]
            :rtype: bool
            """
            i, j = 0, 0
            l = len(nums)
            if l < 3:
                return False
                
            for m in range(1, l):
                if nums[m] > nums[i]:
                    break
                i = m
            
            j = i + 1
            for m in range(i+2, l):
                if nums[m] > nums[j]:
                    return True
                
                if nums[i] < nums[m] < nums[j]: 
                    j = m
                    continue
                
                if nums[m] < nums[i]:
                    i = m
            
            return False

Log in to reply
 

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