当前位置:网站首页>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
边栏推荐
- zabbix 代理服务器 与 zabbix-snmp 监控
- PHP与EXCEL PHPExcel
- Alibaba data source Druid visual monitoring configuration
- [play with Linux] [docker] MySQL installation and configuration
- 思維導圖+源代碼+筆記+項目,字節跳動+京東+360+網易面試題整理
- Zero foundation entry polardb-x: build a highly available system and link the big data screen
- Yyds dry goods inventory leetcode question set 751 - 760
- 激进技术派 vs 项目保守派的微服务架构之争
- Mysql Information Schema 学习(二)--Innodb表
- Leetcode 30. Concatenate substrings of all words
猜你喜欢
语音识别(ASR)论文优选:全球最大的中英混合开源数据TALCS: An Open-Source Mandarin-English Code-Switching Corpus and a Speech
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
Mysql Information Schema 学习(二)--Innodb表
Spark foundation -scala
[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer
Druid database connection pool details
手把手教你学会js的原型与原型链,猴子都能看懂的教程
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
redisson bug分析
利用 clip-path 绘制不规则的图形
随机推荐
Configuration and simple usage of the EXE backdoor generation tool quasar
腾讯字节等大厂面试真题汇总,网易架构师深入讲解Android开发
Low CPU load and high loadavg processing method
Use of map (the data of the list is assigned to the form, and the JSON comma separated display assignment)
short i =1; I=i+1 and short i=1; Difference of i+=1
redisson bug分析
DOM operation
Druid database connection pool details
[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
How to do smoke test
Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
学习打卡web
利用 clip-path 绘制不规则的图形
[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer
技术分享 | 抓包分析 TCP 协议
数据的同步为每个站点创建触发器同步表
Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
From spark csc. csr_ Matrix generate adjacency matrix
算法面试经典100题,Android程序员最新职业规划
Example of applying fonts to flutter