当前位置:网站首页>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;
}
};
边栏推荐
- Graduation summary
- 能解决 80% 故障的排查思路
- 利用DOSBox运行汇编超详细步骤「建议收藏」
- 怎么可以省去大量的switch语句,省去switch语句
- 王者荣耀商城异地多活架构设计
- Wasserstein slim gain with clipping penalty (wsgain-cp) introduction and code implementation -- missing data filling based on generating countermeasure network
- 微信核酸检测预约小程序系统毕业设计毕设(3)后台功能
- Babbitt | metauniverse daily must read: can you buy a virtual anchor for 1000 yuan? Is this the live gospel of small businesses or "cutting leeks"
- 读写 XML/JSON/INI 和 UBJSON 等格式的数据文件的统一接口
- Wechat applet video sharing platform system graduation design completion (1) development outline
猜你喜欢

Nvidia 显卡 Failed to initialize NVML Driver/library version mismatch 错误解决方案

Two pieces of nature a day! Duan Fengfeng, an alumnus of the University of science and technology of China, was the third Chinese winner of the belby medal

Wechat applet video sharing platform system graduation design completion (5) assignment

RDK simulation experiment

Freemaker+poi realizes dynamic generation and parsing of Excel files

Steamos 3.3 beta release, steam deck Chinese keyboard finally came

Picking up the camera is the best artistic healing

win10 kms activator

A good programmer is worth five ordinary programmers!

求求你们,别再刷 Star 了!这跟“爱国”没关系!
随机推荐
Qt官方示例:Qt Quick Controls - Gallery
Deep understanding of ThreadLocal
MySQL -- basic operation of database
Wechat applet video sharing platform system graduation design completion (6) opening defense ppt
微信小程序视频分享平台系统毕业设计毕设(8)毕业设计论文模板
PHP gets the number of days, hours, minutes and seconds between the two timestamps
Unity学习shader笔记[八十一]简单的颜色调整后处理(亮度,饱和度,对比度)
Qt Official examples: Qt Quick Controls - Gallery
Wechat nucleic acid detection appointment applet system graduation design completion (5) task statement
Web聊天工具
Memory mapping of QT
Ora-19838 -- restore control files to the standby database
MySQL -- basic concept of database
【Oracle 期末复习】表空间、表、约束、索引、视图的增删改
[golang | grpc] generate certificates using OpenSSL
Tower safety monitoring system unattended inclination vibration monitoring system
面试,关于线程池的那些事
能解决 80% 故障的排查思路
Wechat nucleic acid detection appointment applet system graduation design (2) applet function
Yingguang MCU development case