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