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. unity3d由于Camera.main.transform报空引用错误的解决方案

    今天在导入character包后,引用了内置的第三人称素材,但是在启动的时候程序报空引用的错误: 引起错误的位置在: 错误原因是因为没有将摄像机的tag设置为maincamera,改为maincame ...

  2. asp.net Login控件基本属性及事件说明

    原文:asp.net Login控件基本属性及事件说明 Login系列控件是微软为了简化我们的开发过程,为我们进行常规的安全开发提供块捷途径. Login系列控件包含下列控件: Login 登录控件 ...

  3. spring问题排查-调低日志等级

    问题描写叙述 1. 页面经过一次改动后,提交后页面出现400错误,可是后台并没有输出不论什么错误信息. 2. debug监听应页面对应的提交链接也没有不论什么反应(没有进入后台的controller方 ...

  4. coco2d-x 基于视口的地图设计

    <pre name="code" class="plain"> 基于视口的地图设计 DionysosLai 2014-06-14 第三人称游戏,玩家 ...

  5. 【原创】shadowebdict开发日记:基于linux的简明英汉字典(一)

    全系列目录: [原创]shadowebdict开发日记:基于linux的简明英汉字典(一) [原创]shadowebdict开发日记:基于linux的简明英汉字典(二) [原创]shadowebdic ...

  6. Mac下改动Android Studio 所用的JDK版本号

    Mac下改动Android Studio 所用的JDK版本号 @author ASCE1885 近期项目从Eclipse+Ant构建模式转移到了Android Studio+Gradle构建模式.自然 ...

  7. REST API 基于ACCESS TOKEN

    REST API 基于ACCESS TOKEN 的权限解决方案   REST 设计原则是statelessness的,而且但客户端是APP时,从APP发起的请求,不是基于bowers,无法带相同的se ...

  8. SQL Server数据库视图

    1:什么是视图 2:视图和查询的区别 3:视图的优点 4:如何创建和管理视图 5:如何通过视图修改基本表的数据 6:如何通过视图实现数据的安全性 A:什么是视图: 视图(view):从一个或几个基本表 ...

  9. Eclipse正确导入第三方project

    前言 昨晚,在不同的Android做出最终的在线测试时间,在其他平台上正常升级的提示突然报告出来"java.lang.NoClassDefFoundError"误.拉什adb lo ...

  10. Akka FSM 源代码分析

    Akka FSM 源代码分析 萧猛 <simonxiao@qq.com> 啰嗦几句 有限状态机本身不是啥新奇东西,在GoF的设计模式一书中就有状态模式, 也给出了实现的建议.各种语言对状态 ...