leetcode -- Maximum Subarray
来源:互联网 发布:c4d mac破解版下载 编辑:程序博客网 时间:2024/05/19 08:39
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.
分析
假设{
因此, maxStr中任一
class Solution {public: int maxSubArray(int A[], int n) { int max = A[0], sum = 0; for(int i = 0; i < n; i++){ sum += A[i]; if(max < sum) max = sum; if(sum < 0) sum = 0; } return max; }};
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
- hdu 5182 PM2.5
- 罡达商务科技发展(湖南)有限公司
- Django中 form表单的使用
- Tarjan算法--有向图强连通分量算法
- 如何创建 Node.js 项目工程
- leetcode -- Maximum Subarray
- win8.1与VC++6.0兼容性问题
- SpringMVC 使用Excel视图
- cpu中断处理
- AS入门(一)
- 算法训练 矩阵乘法
- OA的学习--第一天的内容--环境搭建
- 解决ListView中使用EditText所遇到的一些冲突
- PAT 1020. Tree Traversals (25)