Clean and short nlogn solution
See more explanation in [Longest Increasing Subsequence Size (N log N)][1]\n\n    def maxEnvelopes(self, envelopes):\n        def bin_search(A, key):\n         
See more explanation in [Longest Increasing Subsequence Size (N log N)][1]\n\n    def maxEnvelopes(self, envelopes):\n        def bin_search(A, key):\n            l, r = 0, len(A)\n            while l < r:\n                mid = (l+r)/2\n                if A[mid][1] < key[1]:\n                    l = mid + 1\n                else:\n                    r = mid\n            return l\n        envelopes.sort(\n            cmp = lambda x,y: x[0]-y[0] if x[0] != y[0] else y[1]-x[1])\n        n = len(envelopes)\n        tails = []\n        for i in range(n):\n            e = envelopes[i]\n            p = bin_search(tails, e)\n            if p == len(tails):\n                tails.append(e)\n            else:\n                tails[p] = e\n        return len(tails)\n\n\n  [1]: http://www.geeksforgeeks.org/longest-monotonically-increasing-subsequence-size-n-log-n/
['Python']