Increasing Triplet Subsequence

Problem Id: 334 Difficulty: Medium


Intuition

Solution


class Solution:
    def increasingTriplet(self, nums: List[int]) -> bool:
        first, second, third = None, None, None
        for num in nums:
            if first is None:
                first = num
            else:
                first = min(num, first)

            if first is not None and num > first:
                if second is None:
                    second = num
                else:
                    second = min(second, num)

            if second is not None and num > second:
                return True

        return False