当前位置:网站首页>55. 连续子数组的最大和
55. 连续子数组的最大和
2022-06-28 16:38:00 【hys__handsome】
记录一下经典题标程。
思路
贪心做法:先加上一个数,如果小于0就直接remake。因为完全没必要将负数放在第一个,去掉反而会更好。
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int res = -0x3f3f3f3f, sum = 0;
for(int i = 0,tmp = 0; i < nums.size(); i++){
sum += nums[i];
res = max(res,sum);
if(sum < 0) sum = 0;
//如果nums全为负数则返回最大的负数
}
return res;
}
};dp做法略。
边栏推荐
猜你喜欢

2022年暑期及9月份CSP-J1 CSP-S1初赛 培训计划及学习要点

【Golang】安装 iris 的方法

On the design principle of price discount in SAP software

After the first failure, AMEC rushed to the Hong Kong stock exchange for the second time, and the financial principal changed frequently

Summer Challenge ohos build custom service practice

Briefly introduce the conversion between tensorflow and pytorch (mainly tensorflow to pytorch)

The future of platform as code is kubernetes extension

AI落地的新范式,就“藏”在下一场软件基础设施的重大升级里
![[tcapulusdb knowledge base] tcapulusdb technical support introduction](/img/ae/9295c8ae642cde632d06966c28d342.png)
[tcapulusdb knowledge base] tcapulusdb technical support introduction

Azure Kinect Microsoft camera unity development summary
随机推荐
【力扣】35. 搜索插入位置
Lucky draw animation - Carp jumps over the dragon's gate
如何清除 WordPress 中的缓存
Batchnorm2d principle, function and explanation of batchnorm2d function parameters in pytorch
Five solutions that give consideration to enterprise anti epidemic and development, from IBM
Noip popularization group 2006-2018 preliminary round 2019 csp-j1 2020 csp-j1 improvement program
Lenet5 training model of convolutional neural network for machine learning
GCC efficient graph revolution for joint node representationlearning and clustering
清华大佬耗时3天总结出的'常见网络协议汇总'
【TcaplusDB知识库】查看tcapdir目录服务器
Noip1998-2018 csp-s2 2019 2021 improvement group problem solving report and video
3. Caller 服务调用 - dapr
WPF 视频硬解码渲染播放(无空域)(支持4K、8K、高帧率视频)
Code implementation of gain (4) -- gap dataset missing data filling based on GaN (sequence) [improved version]
Csp-j1 csp-s1 preliminary training plan and learning points in summer and September 2022
Have you ever encountered the error that the main key of this setting is consistent with the database?
Azure Kinect Microsoft camera unity development summary
抓取手机端变体组合思路设想
论文解读(GCC)《Efficient Graph Convolution for Joint Node RepresentationLearning and Clustering》
[tcapulusdb knowledge base] view the business password