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.

动态规划解决方法:
动态规划基本思想(当前N的值由N-1的值推出)
class Solution {
public:
int maxSubArray(int A[], int n) {
int res=A[];
int sum=A[];
for(int i=;i<n;i++)
{
sum=max(sum+A[i],A[i]);
res=max(res,sum); }
return res;
}
};
 

最新文章

  1. SSH框架使用中存在的诡异异常
  2. Spring事务配置的五种方式
  3. VC++ CButton::SetCheck 的使用方法
  4. zepto-创建dom
  5. SQL语句基本概念
  6. js dom操作获取节点的一些方法
  7. 学会用Clang来进行内存泄露分析
  8. (知识点)JavaScript闭包
  9. hdu 6096---String(AC自动机)
  10. 手动导入xmpp后,再使用cocoapods的时候出现的问题
  11. 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II
  12. 聊聊javaMail
  13. Windows Server 2012 NTP时间同步
  14. python与redis
  15. [vue] [axios] 设置代理实现跨域时的纠错
  16. Codeforces.838D.Airplane Arrangements(思路)
  17. Nginx 作为反向Proxy 的优化要点
  18. 使用 NamedScope 扩展 Ninject 的 InRequestScope
  19. SpringBoot实战(六)之使用LDAP验证用户
  20. PHP 基础系列(三) 【转】PHP 函数实现原理及性能分析

热门文章

  1. 基础dp例题整理
  2. UIScrollView控件及其三个常用属性:contentSize、contentInset和contentOffset
  3. [dhcpd]清除dhcp缓存
  4. HDU1255 扫描线 矩形交面积 离散化
  5. oracle重新编译失效对像
  6. linux用户登录指定目录
  7. 剑指offer --合并链表
  8. HDU 5901 Count primes 大素数计数
  9. 注意for循环中变量的作用域
  10. 【点分治练习题&#183;不虚就是要AK】点分治