查看: 1053| 回复: 3
跳转到指定楼层
上一主题 下一主题
收起左侧

[带新人] 请教这道题的时间/空间复杂度

🔗
匿名用户-YOUFK  | 添加认证 | 2021-12-18 15:19:01 |倒序浏览

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
请教一下leetcode 1868. Product of Two Run-Length Encoded Arrays。
这道题用双指针的话,他的时间、空间复杂度是多少,如何计算呢?谢谢

上一篇:nvidia av vs cruise
下一篇:在亚麻,收到pivot,求助关于请病假的细节
🔗
carrotremoval 2021-12-18 15:51:47 | 只看该作者
全局:
Linear time complexity:
  • At each step, at least one of the two pointers will advance past a segment.
  • There exists n+m segments in total, hence there will be at most n+m number of steps.

Constant space complexity (excluding input and output):

  • The state consists of 4 variables: segment1, index_into_segment1, segment2, index_into_segment2.

回复

使用道具 举报

🔗
RocShow 2021-12-18 16:33:12 | 只看该作者
全局:
carrotremoval 发表于 2021-12-17 23:51
Linear time complexity:
  • At each step, at least one of the two pointers will advance past a segme ...

  • +1

    空间复杂度算上output的的话也是m+n
    回复

    使用道具 举报

    地里匿名用户
    🔗
    匿名用户-YOUFK  | 添加认证 | 2021-12-19 07:15:19
    carrotremoval 发表于 2021-12-17 23:51
    Linear time complexity:
  • At each step, at least one of the two pointers will advance past a segme ...

  • 分析有道理, 非常感谢 :)
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册账号
    职场达人
    • ↑ 本版用于讨论职场各种干货话题,闲聊请去🔗聊聊或者🔗匿名版
    • ❌ 本版严禁水贴,引战,发布广告,拉群,贴个人联系方式,扣分无警告
    • ☑ 求职、面经等去 🔗北美求职和 🔗回国求职大区,刷题和学习请去 🔗终身学习大区
    • ☑ 请去专版发布 🔗内推, 🔗招聘信息,和讨论 🔗创业内容
    • ☑ PIP / DevList/ Need Support 等话题也已开设 🔗专版

    本版积分规则

    >
    快速回复 返回顶部 返回列表