dp创始人级精英赛的冠军。最大的部分和。

扫从左至右,保持一个最佳值而当前部分和,在这一部分,并成为负值什么时候。再往下的积累后,也起到了负面作用,所以,放弃直销,然后部分和初始化为阅读的当前位置。

class Solution {
public:
int maxSubArray(int A[], int n) {
int mmax = A[0], tpsum = A[0];
for(int i=1;i<n;i++){
if(tpsum<0) tpsum = A[i];
else tpsum += A[i];
if(tpsum > mmax)
mmax = tpsum;
}
return mmax;
}
};

版权声明:本文博客原创文章。博客,未经同意,不得转载。

leetcode先刷_Maximum Subarray的更多相关文章

  1. [LeetCode] Minimum Size Subarray Sum 解题思路

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  2. LeetCode Maximum Product Subarray(枚举)

    LeetCode Maximum Product Subarray Description Given a sequence of integers S = {S1, S2, . . . , Sn}, ...

  3. [array] leetcode - 53. Maximum Subarray - Easy

    leetcode - 53. Maximum Subarray - Easy descrition Find the contiguous subarray within an array (cont ...

  4. 小旭讲解 LeetCode 53. Maximum Subarray 动态规划 分治策略

    原题 Given an integer array nums, find the contiguous subarray (containing at least one number) which ...

  5. [LeetCode] Maximum Size Subarray Sum Equals k 最大子数组之和为k

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  6. [LeetCode] Minimum Size Subarray Sum 最短子数组之和

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  7. [LeetCode] Maximum Product Subarray 求最大子数组乘积

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  8. LeetCode Maximum Size Subarray Sum Equals k

    原题链接在这里:https://leetcode.com/problems/maximum-size-subarray-sum-equals-k/ 题目: Given an array nums an ...

  9. leetcode-Maximum Subarray

    https://leetcode.com/problems/maximum-subarray/ Find the contiguous subarray within an array (contai ...

随机推荐

  1. 阅读zepto.js的core中的Core methods

    学习zepto.js,參考资料:http://www.zeptojs.cn/ 跟jQuery一样.其选择符号也是$; 首先接触的是 $.()  选择 $(selector, [context]) ⇒ ...

  2. sharepoint 2013 userprofile 用户信息

    Sharepoint2013获得当前用户userfrofile 基本介绍: 什么使用户配置文件. 用户属性和用户配置文件属性提供有关 SharePoint 用户的信息,如显示名称.电子邮件.标题以及其 ...

  3. plist文件读写

    - (void)viewDidLoad { [super viewDidLoad]; NSDictionary *dictionary1 = [NSDictionary dictionaryWithO ...

  4. java split小结(转)

    2016.03.27下午参加华为机试,简单扫了一眼几个题的标题,选择了一道字符串问题,其实该题非常非常的简单,可以说是简单的不能再简单了,而且有很多种解法,上机时我选择了直接借用java提供的一些函数 ...

  5. OCP读书笔记(20) - 复制数据库

    没有连接到target的复制 将orcl数据库的备份复制为orcl1 一.创建orcl的备份: run{ backup database plus archivelog;} 二.复制数据库为orcl1 ...

  6. C陷阱与缺陷之语法陷阱

    2.1理解函数声明 不论什么C变量的声明都由两部分组成:类型以及一组类似表达式的声明符号.比如 float f; 这个声明的含义是:当对其求值时,表达式f和g的类型为浮点数类.由于声 明符与表达式的相 ...

  7. zigbee学习:示例程序SampleApp中通讯流程

    zigbee学习:示例程序SampleApp中通讯流程 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 参考链接: http://wjf88223.bl ...

  8. 程序员之---C语言细节22(函数返回指针注意事项&lt;悬空指针&gt;、查看进程能够分配的内存大小)

    主要内容:函数返回指针注意事项<悬空指针>.查看进程能够分配的内存大小 #include <stdio.h> char * favorite_fruit() { static ...

  9. 3D MAX脚本教程1

    本文转载自http://jiurong995294.blog.163.com/blog/static/195133243201192531546490/ 方便以后须要时候使用 为什么要学习3D MAX ...

  10. yum使用总结(转)

    安装一个软件时yum -y install httpd安装多个相类似的软件时yum -y install httpd*安装多个非类似软件时yum -y install httpd php php-gd ...