V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
缤纷云 - 超高性能🚀 的智能对象存储服务
基于高度自研的架构,我们以 1/3 的成本提供最多 20+ 倍的综合性能增益(对比OSS、Qiniu等主流服务),让你的项目体验得到令人艳羡的提升。
Promoted by nicoljiang
roundRobin
V2EX  ›  算法

蠡口 53 Maximum Subarray 如何用 Divide&Conquer?

  •  
  •   roundRobin · 2019-01-06 14:01:05 +08:00 · 2613 次点击
    这是一个创建于 2434 天前的主题,其中的信息可能已经有所发展或是发生改变。

    不管怎么试都是要遍历一次然后用 DP 来比较最大值,怎样都是 o(n)的复杂度吧?题目的意思用分治能优化吗?求解

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

    Example:

    Input: [-2,1,-3,4,-1,2,1,-5,4], Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6.

    Follow up:

    If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.

    1 条回复    2019-03-10 09:36:19 +08:00
    t9ouKal33vGEZyf5
        1
    t9ouKal33vGEZyf5  
       2019-03-10 09:36:19 +08:00
    小旭讲解 LeetCode 53. Maximum Subarray 分治策略
    https://www.bilibili.com/video/av38950374
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5353 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 06:53 · PVG 14:53 · LAX 23:53 · JFK 02:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.