题目:原题链接(困难)
标签:二分查找、动态规划
解法 | 时间复杂度 | 空间复杂度 | 执行用时 |
Ans 1 (Python) | 64ms (94.13%) | ||
Ans 2 (Python) | |||
Ans 3 (Python) |
解法一:
class Solution:
def maxEnvelopes(self, envelopes: List[List[int]]) -> int:
envelopes = sorted(set((x, y) for x, y in envelopes), key=lambda x: (x[0], -x[1]))
size = len(envelopes)
dp = [float("inf")] * (size + 1)
dp[0] = 0
for x, y in envelopes:
i = bisect.bisect_left(dp, y)
dp[i] = y
return bisect.bisect_right(dp, 20000) - 1