当前位置:网站首页>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
边栏推荐
- Phoenix Architecture 2 - accessing remote services
- How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
- 《数字经济全景白皮书》保险数字化篇 重磅发布
- Low CPU load and high loadavg processing method
- 信息系统项目管理师---第八章 项目质量管理
- 深入分析,Android面试真题解析火爆全网
- The slave i/o thread stops because master and slave have equal MySQL serv
- 腾讯T2大牛亲自讲解,跳槽薪资翻倍
- 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
- 企业精益管理体系介绍
猜你喜欢

Carte de réflexion + code source + notes + projet, saut d'octets + jd + 360 + tri des questions d'entrevue Netease

凤凰架构3——事务处理

Microservice architecture debate between radical technologists vs Project conservatives

Analysis of rainwater connection

10 schemes to ensure interface data security

Learning and Exploration - Seamless rotation map

Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe

Hudi vs Delta vs Iceberg

JDBC details

Leetcode 30. Concatenate substrings of all words
随机推荐
Introduction to enterprise lean management system
Learning and Exploration - function anti shake
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
LeetCode_ Gray code_ Medium_ 89. Gray code
Zero foundation entry polardb-x: build a highly available system and link the big data screen
Blue Bridge Cup microbial proliferation C language
黑馬--Redis篇
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
MySQL information schema learning (II) -- InnoDB table
Simple application of VBA script in Excel
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
USB host driver - UVC swap
350. Intersection of two arrays II
《数字经济全景白皮书》保险数字化篇 重磅发布
深入浅出,面试突击版
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
算法面试经典100题,Android程序员最新职业规划
【翻译】供应链安全项目in-toto移至CNCF孵化器
10 schemes to ensure interface data security
Recursive implementation of department tree