algorithm

334. Increasing Triplet Subsequence

식피두 2020. 9. 3. 19:55

https://leetcode.com/problems/increasing-triplet-subsequence/

 

Increasing Triplet Subsequence - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

find increasing triplet sequence

a < b < c

a_i < b_i < c_i

 

idea: moving minimum!!!!!!

class Solution:
    def increasingTriplet(self, nums: List[int]) -> bool:
        
        left = 0
        mid = -1
        
        for i, n in enumerate(nums):
            l = nums[left]
            m = nums[mid]
            if l > n:
                left = i
            elif mid > -1 and m < n:
                return True
            elif l < n:
                mid = i
            
        return False

'algorithm' 카테고리의 다른 글

1155. Number of Dice Rolls With Target Sum  (0) 2020.09.07
300. Longest Increasing Subsequence  (0) 2020.09.06
473. Matchsticks to Square  (0) 2020.09.03
676. Implement Magic Dictionary  (0) 2020.09.03
662. Maximum Width of Binary Tree  (0) 2020.08.31