当前位置:网站首页>Leetcode 面试题 16.17. 连续数列
Leetcode 面试题 16.17. 连续数列
2022-07-02 16:44:00 【我不是萧海哇~~~~】
给定一个整数数组,找出总和最大的连续数列,并返回总和。
示例:
输入: [-2,1,-3,4,-1,2,1,-5,4]
输出: 6
解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。
进阶:
- 如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的分治法求解。
Code:
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int maxlen=nums[0];
int sum=0;
for(int i=0;i<nums.size();i++)
{
sum=max(nums[i]+sum,nums[i]);
maxlen=max(sum,maxlen);
}
return maxlen;
}
};
边栏推荐
- 微信小程序视频分享平台系统毕业设计毕设(5)任务书
- Outsourcing for five years, abandoned
- 又一所双非改考408,会爆冷么?南昌航空大学软件学院
- Pychar modify pep8 e501 line too long > 0 characters
- 架构设计——ID生成器「建议收藏」
- em120.gige. h
- Aptos tutorial - participate in the official incentive testing network (ait2 incentive testing network)
- Intelligent hydropower meter energy consumption monitoring cloud platform
- MySQL进阶-事务及索引
- Wechat nucleic acid detection and appointment applet system graduation design (3) background function
猜你喜欢
[golang | grpc] generate certificates using OpenSSL
初夏,开源魔改一个带击杀音效的电蚊拍!
Steamos 3.3 beta release, steam deck Chinese keyboard finally came
Intelligent hydropower meter energy consumption monitoring cloud platform
Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline
SteamOS 3.3 Beta 发布,Steam Deck 中文键盘终于来了
RDK simulation experiment
A good programmer is worth five ordinary programmers!
能解决80%故障的排查思路
MySQL安装与配置
随机推荐
Web chat tool
Renren potential field method
Memory mapping of QT
Editor编辑器扩展在Scene View添加按钮和logo
Graduation summary
Wechat applet video sharing platform system graduation design completion (8) graduation design thesis template
win10 kms activator
微信小程序视频分享平台系统毕业设计毕设(5)任务书
再放宽!这些应届生,可直接落户上海
能解决 80% 故障的排查思路
The price is only 40 yuan. Pico development board of raspberry pie is added with WiFi module, and it is out of stock as soon as it comes into the market
Wechat applet video sharing platform system graduation design completion (7) Interim inspection report
Aloam code reading and summary
【西北工业大学】考研初试复试资料分享
Steamos 3.3 beta release, steam deck Chinese keyboard finally came
1288_ Implementation analysis of vtask resume() interface and interrupt Security version interface in FreeRTOS
Easyai notes - machine learning
Chrome officially supports MathML, which is enabled in chromium dev 105 by default
Use Zadig to build a continuous delivery platform from 0 to 1
Wechat nucleic acid detection appointment applet system graduation design completion (4) opening report