LeetCode题解(LCP08):剧情触发时间(Python)
发布日期:2021-06-29 20:15:27 浏览次数:2 分类:技术文章

本文共 761 字,大约阅读时间需要 2 分钟。

题目:(中等)

标签:二分查找

解法 时间复杂度 空间复杂度 执行用时
Ans 1 (Python) O ( N × l o g M ) O(N×logM) O(N×logM) : n=len(requirements) ; m=len(increase) O ( M ) O(M) O(M) 392ms (95.31%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

class Solution:    def getTriggerTime(self, increase: List[List[int]], requirements: List[List[int]]) -> List[int]:        C = [0]        R = [0]        H = [0]        for c, r, h in increase:            C.append(C[-1] + c)            R.append(R[-1] + r)            H.append(H[-1] + h)        ans = []        for c, r, h in requirements:            d1 = bisect.bisect_left(C, c)            d2 = bisect.bisect_left(R, r)            d3 = bisect.bisect_left(H, h)            d = max(d1, d2, d3)            ans.append(d if d <= len(increase) else -1)        return ans

转载地址:https://dataartist.blog.csdn.net/article/details/112564313 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LeetCode题解(LCP12):小张刷题计划(Python)
下一篇:LeetCode题解(LCP19):秋叶收藏集(Python)

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年05月01日 11时25分40秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章