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

2019-01-06 14:01:05 +08:00
 roundRobin

不管怎么试都是要遍历一次然后用 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.

2365 次点击
所在节点    算法
1 条回复
GenialX2
2019-03-10 09:36:19 +08:00
小旭讲解 LeetCode 53. Maximum Subarray 分治策略
https://www.bilibili.com/video/av38950374

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/524356

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX