当前位置:网站首页>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
边栏推荐
- 2022年6月语音合成(TTS)和语音识别(ASR)论文月报
- 【云小课】EI第47课 MRS离线数据分析-通过Flink作业处理OBS数据
- USB host driver - UVC swap
- Phoenix Architecture 3 - transaction processing
- It's enough to read this article to analyze the principle in depth
- [infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
- Example of applying fonts to flutter
- 腾讯字节等大厂面试真题汇总,网易架构师深入讲解Android开发
- Lick the dog until the last one has nothing (simple DP)
- HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
猜你喜欢
腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
Using clip path to draw irregular graphics
MySQL information Schema Learning (i) - - General table
Phoenix Architecture 3 - transaction processing
MySQL information schema learning (I) -- general table
Introduction to enterprise lean management system
Hudi vs Delta vs Iceberg
深度剖析原理,看完这一篇就够了
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
深入浅出,面试突击版
随机推荐
【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
Druid database connection pool details
学习探索-函数防抖
手把手教你学会js的原型与原型链,猴子都能看懂的教程
How to customize animation avatars? These six free online cartoon avatar generators are exciting at a glance!
Learning and Exploration - function anti shake
Selenium advanced operations
部门树递归实现
深度剖析原理,看完这一篇就够了
mod_wsgi + pymssql通路SQL Server座
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
MySQL information Schema Learning (i) - - General table
凤凰架构3——事务处理
MySql必知必会学习
Mysql Information Schema 学习(二)--Innodb表
在解决了 2961 个用户反馈后,我做出了这样的改变...
Mysql Information Schema 学习(一)--通用表
DaGAN论文解读
A5000 vGPU显示模式切换
精彩编码 【进制转换】