当前位置:网站首页>Leetcode brush first_ Maximum Subarray
Leetcode brush first_ Maximum Subarray
2022-07-06 19:49:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
dp The champion of Founder level elite . The largest part and .
Sweep from left to right , Maintain an optimal value while the current part and , In this part , And become negative when . After further accumulation , Also played a negative role , therefore , Abandon direct selling , Then partial sum is initialized to the current position of reading .
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;
}
};Copyright notice : This article is an original blog article . Blog , Without consent , Shall not be reproduced .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117150.html Link to the original text :https://javaforall.cn
边栏推荐
- 121. 买卖股票的最佳时机
- 关于图像的读取及处理等
- Logstash expressway entrance
- 学习打卡web
- [infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
- 腾讯T3大牛手把手教你,大厂内部资料
- MySQL must know and learn
- Interview assault 63: how to remove duplication in MySQL?
- 2022年6月语音合成(TTS)和语音识别(ASR)论文月报
- HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
猜你喜欢

Zero foundation entry polardb-x: build a highly available system and link the big data screen
![[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.](/img/09/106adc222c06cbd2f4f66cf475cce2.jpg)
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.

Spark foundation -scala

Using clip path to draw irregular graphics

Microservice architecture debate between radical technologists vs Project conservatives

《数字经济全景白皮书》保险数字化篇 重磅发布

Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting

Standardized QCI characteristics

信息系统项目管理师---第八章 项目质量管理

社招面试心得,2022最新Android高频精选面试题分享
随机推荐
深入分析,Android面试真题解析火爆全网
From spark csc. csr_ Matrix generate adjacency matrix
leetcode先刷_Maximum Subarray
颜色(color)转换为三刺激值(r/g/b)(干股)
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
redisson bug分析
Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
It's enough to read this article to analyze the principle in depth
Zero foundation entry polardb-x: build a highly available system and link the big data screen
JDBC details
CF960G - Bandit Blues(第一类斯特林数+OGF)
The slave i/o thread stops because master and slave have equal MySQL serv
Transformer model (pytorch code explanation)
学习探索-函数防抖
MySQL must know and learn
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
How to do smoke test
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
Hudi vs Delta vs Iceberg
Mysql Information Schema 学习(一)--通用表