当前位置:网站首页>leetcode先刷_Maximum Subarray
leetcode先刷_Maximum Subarray
2022-07-06 11:48:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
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;
}
};版权声明:本文博客原创文章。博客,未经同意,不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117150.html原文链接:https://javaforall.cn
边栏推荐
- How to access localhost:8000 by mobile phone
- 深度剖析原理,看完这一篇就够了
- 接雨水问题解析
- C # - realize serialization with Marshall class
- [translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
- Black Horse - - Redis Chapter
- USB host driver - UVC swap
- 【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
- 1805. Number of different integers in the string
- 企业精益管理体系介绍
猜你喜欢
![[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system](/img/63/3addcecb69dcb769c4736653952f66.png)
[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system

MySQL information schema learning (II) -- InnoDB table

Using clip path to draw irregular graphics

如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!

面试突击63:MySQL 中如何去重?
![[玩转Linux] [Docker] MySQL安装和配置](/img/04/6253ef9fdf7d2242b42b4c7fb2c607.png)
[玩转Linux] [Docker] MySQL安装和配置

反射及在运用过程中出现的IllegalAccessException异常

Mysql Information Schema 学习(二)--Innodb表

Interview assault 63: how to remove duplication in MySQL?

蓝桥杯 微生物增殖 C语言
随机推荐
Configuration and simple usage of the EXE backdoor generation tool quasar
Using clip path to draw irregular graphics
手把手教你学会js的原型与原型链,猴子都能看懂的教程
DOM operation
Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
Leetcode 30. 串联所有单词的子串
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
POJ 3207 Ikki&#39;s Story IV – Panda&#39;s Trick (2-SAT)
How to customize animation avatars? These six free online cartoon avatar generators are exciting at a glance!
Tencent Android interview must ask, 10 years of Android development experience
部门树递归实现
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
[pytorch] yolov5 train your own data set
MySQL information Schema Learning (i) - - General table
How to do smoke test
MySql必知必会学习
Test Li hi
颜色(color)转换为三刺激值(r/g/b)(干股)
在解决了 2961 个用户反馈后,我做出了这样的改变...