当前位置:网站首页>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
边栏推荐
- Unbalance balance (dynamic programming, DP)
- Finally, there is no need to change a line of code! Shardingsphere native driver comes out
- Documents to be used in IC design process
- MySQL information schema learning (II) -- InnoDB table
- (3) Web security | penetration testing | basic knowledge of network security construction, IIS website construction, EXE backdoor generation tool quasar, basic use of
- In depth analysis, Android interview real problem analysis is popular all over the network
- 冒烟测试怎么做
- CPU负载很低,loadavg很高处理方法
- How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
- It's super detailed in history. It's too late for you to read this information if you want to find a job
猜你喜欢

通俗的讲解,带你入门协程

JDBC details

蓝桥杯 微生物增殖 C语言

Documents to be used in IC design process

VMware virtual machine cannot open the kernel device "\.\global\vmx86"

Spark foundation -scala

接雨水问题解析

Zero foundation entry polardb-x: build a highly available system and link the big data screen

Interview assault 63: how to remove duplication in MySQL?

深度剖析原理,看完这一篇就够了
随机推荐
Mysql Information Schema 学习(一)--通用表
DaGAN论文解读
MySQL must know and learn
Blue Bridge Cup microbial proliferation C language
腾讯T3手把手教你,真的太香了
系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
Hudi vs Delta vs Iceberg
In depth analysis, Android interview real problem analysis is popular all over the network
Spark foundation -scala
【翻译】供应链安全项目in-toto移至CNCF孵化器
[translation] Digital insider. Selection process of kubecon + cloudnativecon in Europe in 2022
Reflection and illegalaccessexception exception during application
学习打卡web
Carte de réflexion + code source + notes + projet, saut d'octets + jd + 360 + tri des questions d'entrevue Netease
Vscode debug run fluent message: there is no extension for debugging yaml. Should we find yaml extensions in the market?
An error occurs when installing MySQL: could not create or access the registry key needed for the
DOM operation
POJ 3207 Ikki&#39;s Story IV – Panda&#39;s Trick (2-SAT)
Leetcode 30. 串联所有单词的子串
Interpretation of Dagan paper