Python simple code inspired by others


  • 0
    P
    from bisect import bisect_left
    class Solution(object):
    	def maxEnvelopes(self, envelopes):
    		"""
    		:type envelopes: List[List[int]]
    		:rtype: int
    		"""
    		es = [ e[1] for e in sorted( envelopes, key=lambda x: (x[0], -x[1]))]
    		res = []
    		for e in es:
    			pos = bisect_left( res, e )
    			if pos >= len(res):
    				res.append( e )
    			else:
    				res[pos] = e
    		return len(res)
    

    Learned from:
    Giiia' solution
    and
    dietpepsi's explannation
    Thanks to them!


Log in to reply
 

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