当前位置:网站首页>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做法略。
边栏推荐
- apache 设置timeout参数
- Please ask me, the queries written in my database account for 99%. Is it better to use pay as you go mode or reservation mode?
- Js中的Bom
- NOIP普及组2006-2018初赛 2019 CSP-J1 2020 CSP-J1 完善程序题
- 2019 CSP J2 entry group csp-s2 improvement group round 2 video and question solution
- How to log in to your WordPress admin dashboard
- 【Hot100】3. Longest substring without duplicate characters
- 共享主机和 WordPress 主机之间的区别
- Have you ever encountered the error that the main key of this setting is consistent with the database?
- Super automation and the future of network security
猜你喜欢

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

使用 Open Connector 进行 HubSpot 和 SAP 系统的集成工作

The future of platform as code is kubernetes extension

基于DataWorks的时效仿真平台|得物技术

PotPlayer播放百度云盘视频

Curve 替换 Ceph 在网易云音乐的实践

Csp-j1 csp-s1 preliminary training plan and learning points in summer and September 2022

Internet of things cloud convergence Security Guide

清华大佬耗时3天总结出的'常见网络协议汇总'

中国SSD行业企业势力全景图
随机推荐
Gartner announces five privacy trends from today to 2024
Can SQL queries be used in the tablestore to find out all the data in the table?
CRM 全栈开发工具 WebClient UI Workbench 的设计细节介绍
【TcaplusDB知识库】WebClient用户如何读取和修改数据
[tcaplusdb knowledge base] view tcapdir directory server
Must the database primary key be self incremented? What scenarios do not suggest self augmentation? ByteDance experience sharing using Flink state 𞓜 afternoon tea with sauce issue 16
Lucky draw animation - Carp jumps over the dragon's gate
基于DataWorks的时效仿真平台|得物技术
【TcaplusDB知识库】TcaplusDB技术支持介绍
O & M - unified gateway is very necessary
Inspur network wins step by step
Convolutional neural networks for machine learning -- an introduction to CNN
通过setTimeout解决子组件不会销毁的问题
[redis] a brief summary of redis on January 31, 2021 No.01
np tips: random 创建随机矩阵 sample = np.random.random([19, 64 , 64, 3])
js中订阅发布模式bus
【力扣】977. 有序数组的平方
抓取手机端变体组合思路设想
Slim gain (sgain) introduction and code implementation -- missing data filling based on generated countermeasure network
Convolutional neural network for machine learning uses cifar10 data set and alexnet network model to train classification model, install labelimg, and report error