Skip to main content

334 - Increasing Triplet Subsequence

Details

KeyValue
Linkhttps://leetcode.com/problems/increasing-triplet-subsequence/submissions/
LanguagePython 3
Runtime1634 ms, faster than 15.21% of Python3 online submissions for Increasing Triplet Subsequence
Memory Usage24.6 MB, less than 49.03% of Python3 online submissions for Increasing Triplet Subsequence
DatastructuresList[str]
AlgorithmsBinary Search?
ComplexityTime: O(NlogN) Memory: O(1)

Procedure

  1. ...

Code

class Solution:
def increasingTriplet(self, nums: List[int]) -> bool:
first = second = float('inf')

for num in nums:
if num <= first: first = num
elif num <= second: second = num
else: return True

return False