Simple O(n log n) Python solution using bisect


  • 1
    P
    from bisect import bisect_left
    
    class Solution(object):
        def lengthOfLIS(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            l = []
            for n in nums:
                i = bisect_left(l, n)
                if i == len(l):
                    l.append(n)
                else:
                    l[i] = n
            return len(l)

  • 0
    M
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.