当前位置:网站首页>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
边栏推荐
- Selenium advanced operations
- Tencent Android interview must ask, 10 years of Android development experience
- MySQL must know and learn
- 方法关键字Deprecated,ExternalProcName,Final,ForceGenerate
- Alibaba数据源Druid可视化监控配置
- 【翻译】供应链安全项目in-toto移至CNCF孵化器
- JDBC details
- 350. Intersection of two arrays II
- Cf960g - bandit Blues (type I Stirling number +ogf)
- 信息系统项目管理师---第八章 项目质量管理
猜你喜欢

潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
![[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)](/img/1e/b270a81c8457f1eae34f55c004a01a.png)
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
腾讯T2大牛亲自讲解,跳槽薪资翻倍
时钟轮在 RPC 中的应用

How to access localhost:8000 by mobile phone

深度剖析原理,看完这一篇就够了

Using clip path to draw irregular graphics

腾讯T3手把手教你,真的太香了

Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)

学习探索-无缝轮播图
随机推荐
PHP与EXCEL PHPExcel
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
部门树递归实现
接雨水问题解析
121. The best time to buy and sell stocks
After solving 2961 user feedback, I made such a change
颜色(color)转换为三刺激值(r/g/b)(干股)
Method keywords deprecated, externalprocname, final, forcegenerate
学习探索-函数防抖
从sparse.csc.csr_matrix生成邻接矩阵
Interview assault 63: how to remove duplication in MySQL?
学习探索-无缝轮播图
蓝桥杯 微生物增殖 C语言
[play with Linux] [docker] MySQL installation and configuration
Druid database connection pool details
Introduction to enterprise lean management system
学习探索-使用伪元素清除浮动元素造成的高度坍塌
(3) Web security | penetration testing | basic knowledge of network security construction, IIS website construction, EXE backdoor generation tool quasar, basic use of
Mysql Information Schema 學習(一)--通用錶
Tencent Android interview must ask, 10 years of Android development experience