当前位置:网站首页>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
边栏推荐
- How to access localhost:8000 by mobile phone
- USB host driver - UVC swap
- Looting iii[post sequence traversal and backtracking + dynamic planning]
- Introduction to enterprise lean management system
- 算法面试经典100题,Android程序员最新职业规划
- Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
- Elastic search indexes are often deleted [closed] - elastic search indexes gets deleted frequently [closed]
- Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
- MySQL information schema learning (II) -- InnoDB table
- 手把手教你学会js的原型与原型链,猴子都能看懂的教程
猜你喜欢
Black Horse - - Redis Chapter
Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法
在解决了 2961 个用户反馈后,我做出了这样的改变...
算法面试经典100题,Android程序员最新职业规划
【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
Interpretation of Dagan paper
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
CPU负载很低,loadavg很高处理方法
保证接口数据安全的10种方案
随机推荐
信息系统项目管理师---第八章 项目质量管理
MySQL information schema learning (I) -- general table
Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
An error occurs when installing MySQL: could not create or access the registry key needed for the
Translation D28 (with AC code POJ 26:the nearest number)
Tensorflow2.0 self defined training method to solve function coefficients
Learning and Exploration - function anti shake
Phoenix Architecture 2 - accessing remote services
学习探索-函数防抖
js实现力扣71题简化路径
系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
Phoenix Architecture 3 - transaction processing
Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand
腾讯T3手把手教你,真的太香了
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
Swagger2 reports an error illegal DefaultValue null for parameter type integer
Classic 100 questions of algorithm interview, the latest career planning of Android programmers
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
面试突击63:MySQL 中如何去重?