LeetCode-Maximum Subarray
来源:互联网 发布:做网络推广的公司 编辑:程序博客网 时间:2024/05/17 05:58
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
For example, given the array [−2,1,−3,4,−1,2,1,−5,4]
,
the contiguous subarray [4,−1,2,1]
has the largest sum = 6
.
click to show more practice.
More practice:
Solution:If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.
Code:
<span style="font-size:14px;">class Solution {public: int maxSubArray(int A[], int n) { int result = A[0]; for (int i = 1; i < n; ++i) { A[i] = max(A[i], A[i-1]+A[i]); result = max(result, A[i]); } return result; }};</span>
0 0
- 【LeetCode】Maximum Subarray 和 Maximum Product Subarray
- LeetCode: Maximum Subarray
- LeetCode Maximum Subarray
- [Leetcode] Maximum Subarray
- LeetCode: Maximum Subarray
- leetcode 25: Maximum Subarray
- [LeetCode] Maximum Subarray
- [Leetcode] Maximum Subarray
- [LeetCode]Maximum Subarray
- [leetcode]Maximum Subarray
- LeetCode-Maximum Subarray
- [leetcode] Maximum Subarray
- LeetCode 45: Maximum Subarray
- LeetCode - Maximum Subarray
- LeetCode:Maximum Subarray
- LeetCode 53: Maximum Subarray
- 【leetcode】Maximum Subarray
- Leetcode Maximum Subarray
- UVA434 - Matty's Blocks
- poj-3225
- 一个简单的数字记忆训练软件介绍
- (14)Android监听时return 返回的false与true的区别
- lsnrctl 中 关于status 状态的说明
- LeetCode-Maximum Subarray
- axis2 jar包详解及缺少jar包错误分析
- 【LeetCode】LRU Cache
- UITableView tableHeaderView touch
- java 中的String类
- 2014-C第1周项目——初步体验分支结构和循环结构的程序设计 3 三数中的最大值
- JAVAWEB常见缺包异常
- 括号配对问题
- Linux进阶——查看进程ps命令