[Leetcode] Maximum Subarrary
来源:互联网 发布:淘宝蓝海类目 编辑:程序博客网 时间:2024/05/09 13:41
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
.
都是负数的话返回最大的负数。
class Solution {public: int maxSubArray(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n==0) return 0; int tempSum = A[0]; int maxSum = tempSum; for(int i=1;i<n;i++) { if(tempSum<=0) { tempSum = A[i]; } else { tempSum += A[i]; } maxSum = max(tempSum,maxSum); } return maxSum; }};
- [Leetcode] Maximum Subarrary
- Maximum Subarrary
- LeetCode: Maximum Subarray
- LeetCode Maximum Subarray
- [Leetcode] Maximum Subarray
- LeetCode: Maximum Subarray
- leetcode 25: Maximum Subarray
- [LeetCode] Maximum Subarray
- [Leetcode] Maximum Subarray
- leetcode Sliding Window Maximum
- [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
- Rails3程序在产品模式下出现assert文件404错误的问题
- POJ 3026 广搜+最小生成树
- JSP/Servlet:tomcat深入内部结构描述
- UltraISO 写入 U 盘安装 Ubuntu
- WordPress提交评论后自动跳转到“Thank you” 页面
- [Leetcode] Maximum Subarrary
- 你中招了吗?iOS应用泄露隐私比安卓严重
- Android Custom Dialog错误Unable to add window -- token null is not for an application
- srm144div2P200简单题
- 互联网传统进入要交的学费-怎么样才能成功
- C语言——字符I/O与缓冲区
- ETL百科
- 选择排序
- 分享成为高效程序员的7个重要习惯