letcode code]Maximum Subarray
1 题目:
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.
maxSum = Math.max(maxSum, curSum);
改为if语句,存开始序号和子串长度。
public int maxSubArray(int[] A){
if (A.length == 0) {
return 0;
}
int maxSum = A[0];
int curSum = A[0];
int len = A.length;
for (int i = 1; i < len; i++) {
curSum = Math.max(curSum + A[i], A[i]);
maxSum = Math.max(maxSum, curSum);
}
return maxSum;
}
letcode code]Maximum Subarray的更多相关文章
- maximum subarray problem
In computer science, the maximum subarray problem is the task of finding the contiguous subarray wit ...
- Maximum Subarray Sum
Maximum Subarray Sum 题意 给你一个大小为N的数组和另外一个整数M.你的目标是找到每个子数组的和对M取余数的最大值.子数组是指原数组的任意连续元素的子集. 分析 参考 求出前缀和, ...
- [array] leetcode - 53. Maximum Subarray - Easy
leetcode - 53. Maximum Subarray - Easy descrition Find the contiguous subarray within an array (cont ...
- 53. Maximum Subarray最大求和子数组12 3(dp)
[抄题]: Find the contiguous subarray within an array (containing at least one number) which has the la ...
- [LeetCode] Maximum Subarray Sum
Dynamic Programming There is a nice introduction to the DP algorithm in this Wikipedia article. The ...
- [LintCode] Maximum Subarray 最大子数组
Given an array of integers, find a contiguous subarray which has the largest sum. Notice The subarra ...
- 【leetcode】Maximum Subarray (53)
1. Maximum Subarray (#53) Find the contiguous subarray within an array (containing at least one nu ...
- 算法:寻找maximum subarray
<算法导论>一书中演示分治算法的第二个例子,第一个例子是递归排序,较为简单.寻找maximum subarray稍微复杂点. 题目是这样的:给定序列x = [1, -4, 4, 4, 5, ...
- LEETCODE —— Maximum Subarray [一维DP]
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which ...
随机推荐
- WIN7成功安装Qt4.8方法,无需VS支持
下载地址:http://pan.baidu.com/share/link?shareid=159827&uk=4010603727 安装Qt方法 安装准备:1. qt-win-opensour ...
- include 指令和 include 动作引入 jsp 页面时中文乱码
include指令:<%@ include file="new.jsp" %> include动作:<jsp:include page="new.jsp ...
- wcf 使用sqlMembership证书认证
.接口 namespace Aretch.WcfService.Services.Interface { [ServiceContract] public interface ICalculator ...
- Maximum Average Subarray II LT644
Given an array consisting of n integers, find the contiguous subarray whose length is greater than o ...
- nginx 动静分离 以及 负载均衡配置
测试环境 系统版本:win7 Nginx版本:nginx-1.8.1 Tomcat版本:tomcat-6.0.14 1动静分离配置 Nginx.conf 中 server中 server { list ...
- Armadillo installation
1.dependencies sudo apt-get install libopenblas-devsudo apt-get install liblapack-devsudo apt-get in ...
- 如何在Eclipse下安装SVN插件——subclipse
如何在Eclipse下安装SVN插件——subclipse | 浏览:2799 | 更新:2014-09-20 22:39 1 2 3 4 5 6 分步阅读 版本控制是开发人员必不可少的工具,而SVN ...
- 用windows计划任务执行一些内容的写法,
用windows计划任务执行一些内容的写法, 以下示例: 1.创建ws对象 2.关闭java进程 3.执行bat文件 start.vbe文件内容 set ws=wscript.createobject ...
- 【转载】 H264的I/P/B帧类型判断
http://blog.csdn.net/zhuweigangzwg/article/details/44152239 这里首先说明下H264的结构: 00 00 00 01/00 00 01-> ...
- zk实现分布式锁
public interface lock { void getLock(); void unLock(); } public abstract class ZkAbstractLock implem ...