根据Leetcode上俄罗斯套娃的程序改进了一下 class Solution: def maxEnvelopes(self, envelopes): if not envelopes: return 0 n = len(envelopes) envelopes.sort(key=lambda x: (x[0] + x[1])) f = [1] * n for i in range(n): for j in range(i): if max(envelopes[i]) > max(envelopes[j]) and min(envelopes[i]) > min(envelopes[j]): f[i] = max(f[i], f[j]+1) return print(max(f))
牛客网
牛客企业服务