当前位置:网站首页>Sword finger offer 42 Maximum sum of successive subarrays
Sword finger offer 42 Maximum sum of successive subarrays
2022-06-23 06:42:00 【zmm_ mohua】
The finger of the sword Offer 42. The maximum sum of successive subarrays
subject

Code
#include <iostream>
#include <vector>
using namespace std;
int maxSubArray(vector<int>& nums) {
int n = nums.size();
if(n == 0){
return 0;
}else if(n == 1){
return nums[0];
}
vector<int> dp(n);
dp[0] = nums[0];
int res = nums[0];
for(int i = 1; i < n; i++){
dp[i] = max(dp[i-1] + nums[i], nums[i]);
res = max(res, dp[i]);
}
return res;
}
int main(){
int n, res;
cin>>n;
vector<int> nums(n);
for(int i = 0; i < n; i++){
cin>>nums[i];
}
res = maxSubArray(nums);
cout<<res;
return 0;
}
边栏推荐
- 记一次GLIB2.14升级GLIB2.18的记录以及其中的步骤原理
- QT creator builds osgearth environment (osgqt msvc2017)
- minio单节点部署 minio分布式部署 傻瓜式部署过程 (一)
- 射频内容学习
- Kubesphere offline deployment without network environment
- English语法_副词 - ever / once
- Docker实战 -- 部署Redis集群与部署微服务项目
- mars3d点线面的绘制和重置
- Sklearn classification in sklearn_ Report & accuracy / recall /f1 value
- vs+qt项目转qt creator
猜你喜欢

Day_ 03 smart communication health project - appointment management - inspection team management

常见设置模式(抽象工厂&责任链模式&观察者模式)

设计师需要懂的数据指标与数据分析模型

聚焦智慧城市,华为携手中科星图共同开拓数字化新蓝海

Day_ 12 smart health project jasperreports

Day_ 05 smart communication health project - appointment management - appointment settings

什么是客户体验自动化?

光谱共焦的测量原理及厚度测量模式

20220621 Three Conjugates of Dual Quaternions

如何实现与FDA保持邮件通信安全加密?
随机推荐
解析创客教育中的个性化学习进度
Link of Baidu URL parameter? Research on URL parameter encryption and decryption (code example)
C Advanced Learning -- Reflection
Vs+qt project transferred to QT Creator
Day_ 09 smart health project - mobile terminal development - Mobile quick login and permission control
leetcode - 572. 另一棵树的子树
sklearn sklearn中classification_report&精确度/召回率/F1值
杂七杂八的东东
Plot+seaborn+folium: a visual exploration of Abbey's rental housing data
C语言去除字符串尾部的换行(或其他字符)
haas506 2.0开发教程-高级组件库-modem.sim(仅支持2.2以上版本)
Xray linkage crawlergo automatic scanning pit climbing record
haas506 2.0开发教程-hota(仅支持2.2以上版本)
什么是PDCA循环?如何整合 PDCA 循环和 OKR
idea的去除转义的复制粘贴
疫情下的传媒产业,小程序生态驱动数字化转型探索
sklearn sklearn中的模型调参利器 gridSearchCV(网格搜索)
Open source to the world (Part 2): the power of open source from the evolution of database technology BDTC 2021
Mysql5.6 (5.7-8) is based on shardingsphere5.1.1 sharding proxy mode. Read / write separation
Machine learning artifact scikit learn minimalist tutorial