Python NLogN solution


  • 0
    from bisect import *
    
    class Solution(object):
        def maxEnvelopes(self, envelopes):
            n = len(envelopes)
            envelopes.sort(key = lambda x : x[1], reverse=True)
            envelopes.sort(key = lambda x : x[0])
            maxLen = 0; minTailOfSize = [0]*n
            for envelope in envelopes:
                j = bisect_left(minTailOfSize, envelope[1], 0, maxLen)
                minTailOfSize[j] = envelope[1]
                if j == maxLen: maxLen += 1
            return maxLen
    

Log in to reply
 

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