当前位置:网站首页>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
边栏推荐
- 利用 clip-path 绘制不规则的图形
- Hudi vs Delta vs Iceberg
- 1805. 字符串中不同整数的数目
- 【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
- MySQL information schema learning (II) -- InnoDB table
- USB host driver - UVC swap
- JDBC details
- Using clip path to draw irregular graphics
- MySQL information schema learning (I) -- general table
- 凤凰架构3——事务处理
猜你喜欢

Phoenix Architecture 3 - transaction processing

利用 clip-path 绘制不规则的图形

在解决了 2961 个用户反馈后,我做出了这样的改变...

It's enough to read this article to analyze the principle in depth

10 schemes to ensure interface data security
腾讯T2大牛亲自讲解,跳槽薪资翻倍
![[玩转Linux] [Docker] MySQL安装和配置](/img/04/6253ef9fdf7d2242b42b4c7fb2c607.png)
[玩转Linux] [Docker] MySQL安装和配置

After solving 2961 user feedback, I made such a change

spark基础-scala

How to access localhost:8000 by mobile phone
随机推荐
leetcode先刷_Maximum Subarray
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
Phoenix Architecture 2 - accessing remote services
CPU负载很低,loadavg很高处理方法
Interview assault 63: how to remove duplication in MySQL?
It's enough to read this article to analyze the principle in depth
技术分享 | 抓包分析 TCP 协议
Configuration and simple usage of the EXE backdoor generation tool quasar
面试突击63:MySQL 中如何去重?
蓝桥杯 微生物增殖 C语言
short i =1; I=i+1 and short i=1; Difference of i+=1
ZABBIX proxy server and ZABBIX SNMP monitoring
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
方法关键字Deprecated,ExternalProcName,Final,ForceGenerate
腾讯字节等大厂面试真题汇总,网易架构师深入讲解Android开发
Vscode debug run fluent message: there is no extension for debugging yaml. Should we find yaml extensions in the market?
Use of map (the data of the list is assigned to the form, and the JSON comma separated display assignment)
Dom 操作
学习探索-函数防抖
Learning and Exploration - function anti shake