LIS
有点杀鸡用牛刀的嫌疑
单调栈
时间复杂性达标, 空间需要O(n)
import sys
class Solution(object):
def increasingTriplet(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
p_f1 = sys.maxint
p_f2 = sys.maxint
for n in nums:
if n > p_f2:
return True
if n <= p_f1:
p_f1 = n
else:
p_f2 = n
return False
网友评论