美文网首页LeetCode
334. 递增的三元子序列

334. 递增的三元子序列

作者: cptn3m0 | 来源:发表于2019-03-19 20:55 被阅读0次

    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
    

    相关文章

      网友评论

        本文标题:334. 递增的三元子序列

        本文链接:https://www.haomeiwen.com/subject/clhomqtx.html