0
点赞
收藏
分享

微信扫一扫

LeetCode题解(0354):俄罗斯套娃信封问题(Python)


题目:​​原题链接​​(困难)

标签:二分查找、动态规划

解法

时间复杂度

空间复杂度

执行用时

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


举报

相关推荐

0 条评论