Python correct for small data, Time Out


  • 0
    W
    class Solution(object):
        def maxEnvelopes(self, envelopes):
            """
            :type envelopes: List[List[int]]
            :rtype: int
            """
            n=len(envelopes)
            if n<=1:
                return n
            d=[1 for i in range(n)]
            def helper(k):
                r=d[k]
                for j in range(n):
                    if envelopes[k][0]>envelopes[j][0] and envelopes[k][1]>envelopes[j][1]:
                        r=max(r,helper(j)+1)
                return r
            for i in range(n):
                d[i]=helper(i)
            return max(d)

Log in to reply
 

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