当前位置:网站首页>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;
}
};
边栏推荐
- Please, stop painting star! This has nothing to do with patriotism!
- 初夏,开源魔改一个带击杀音效的电蚊拍!
- Wasserstein slim gain with clipping penalty (wsgain-cp) introduction and code implementation -- missing data filling based on generating countermeasure network
- 2020 Internet industry terminology
- 王者荣耀商城异地多活架构设计
- Laravel框架安装时遇到的坑
- 微信小程序视频分享平台系统毕业设计毕设(4)开题报告
- 719. Find the distance of the number pair with the smallest K
- Simple understanding of cardinality sorting
- Intelligent hydropower meter energy consumption monitoring cloud platform
猜你喜欢

In Linux, MySQL sets the job task to start automatically

MySQL installation and configuration

MySQL -- basic operation of database

如何开启IDEA的Run Dashboard功能

自定义一个loading指令

Wechat applet video sharing platform system graduation design completion (7) Interim inspection report

好玩的免费GM游戏整理汇总

Deep understanding of ThreadLocal

1288_ Implementation analysis of vtask resume() interface and interrupt Security version interface in FreeRTOS

Pit encountered during installation of laravel frame
随机推荐
wait_ for_ Gap -- restore archive from primary archive to secondary Archive
Pychar modify pep8 e501 line too long > 0 characters
微信小程序视频分享平台系统毕业设计毕设(3)后台功能
977. Square of ordered array
Freemaker+poi realizes dynamic generation and parsing of Excel files
Modbus protocol communication exception
Use Zadig to build a continuous delivery platform from 0 to 1
em120.gige. h
SteamOS 3.3 Beta 发布,Steam Deck 中文键盘终于来了
国金证券是国企吗?在国金证券开户资金安全吗?
微信小程序视频分享平台系统毕业设计毕设(1)开发概要
实施阴影介绍
Wechat applet video sharing platform system graduation design completion (7) Interim inspection report
Wechat nucleic acid detection appointment applet system graduation design (2) applet function
Use dosbox to run the assembly super detailed step "suggestions collection"
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
读写 XML/JSON/INI 和 UBJSON 等格式的数据文件的统一接口
Unity学习shader笔记[八十一]简单的颜色调整后处理(亮度,饱和度,对比度)
Redisson high performance redis distributed lock source code analysis
Bluetooth technology | new working mode of wearable devices of the Internet of things, and Bluetooth ble helps the new working mode