V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
roundRobin
V2EX  ›  算法

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

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

    不管怎么试都是要遍历一次然后用 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
    GenialX2
        1
    GenialX2  
       2019-03-10 09:36:19 +08:00
    小旭讲解 LeetCode 53. Maximum Subarray 分治策略
    https://www.bilibili.com/video/av38950374
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1103 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 18:34 · PVG 02:34 · LAX 11:34 · JFK 14:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.