给定一个未排序的数组,判断这个数组中是否存在长度为 3 的递增子序列。
方案一:res[0]存储递增序列的最小起点,res[1]存储递增序列第二位的最小值
class Solution(object):
def increasingTriplet(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
res = [float('inf'), float('inf')]
i = 0
for n in nums:
if n > res[1]:
return True
if n <= res[0]:
res[0] = n
else:
res[1] = n
return False