Increasing Triplet Subsequence - python solution-sharing


  • 0
    C
    class Solution(object):
        def increasingTriplet(self, nums):
            """
            :type nums: List[int]
            :rtype: bool
            """
            dic = {"B":None,"M":None,"S":None} # (B)ig (M)iddle (S)mall
            for index in range(0, len(nums))[::-1]:
                if nums[index]==dic["B"]:
                    continue
                if nums[index]>dic["B"]:
                    dic["B"] = nums[index]
                    dic["M"] = None
                    continue
                if nums[index]==dic["M"]:
                    continue
                if nums[index]>dic["M"]:
                    dic["M"] = nums[index]
                    continue
                if nums[index]>dic["S"]:
                    dic["S"] = nums[index]
                    return True
            return False

Log in to reply
 

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