当前位置:网站首页>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;
}
};
边栏推荐
- Win10 uninstall CUDA
- Wechat applet video sharing platform system graduation design completion (4) opening report
- Export Excel files using npoi
- MySQL安装与配置
- Hbuilderx runs to the mobile phone or simulator and prompts that the device is not found
- C# 检测图片是否被旋转并修改到正真的旋转
- Memory mapping of QT
- How can you omit a large number of switch statements
- Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline
- 读写 XML/JSON/INI 和 UBJSON 等格式的数据文件的统一接口
猜你喜欢

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

巴比特 | 元宇宙每日必读:一千块就能买一个虚拟主播?这是小企业的直播福音还是在“割韭菜”?...
![[games101] operation 4 B é zier curve](/img/57/e7a9191b959cb1177b7bd1a439df2a.png)
[games101] operation 4 B é zier curve

Intelligent hydropower meter energy consumption monitoring cloud platform

微信核酸检测预约小程序系统毕业设计毕设(1)开发概要

Summary of fun free GM games

Wechat applet video sharing platform system graduation design completion (4) opening report

Aloam code reading and summary

Hbuilderx runs to the mobile phone or simulator and prompts that the device is not found

pycharm 修改 pep8 E501 line too long > 0 characters
随机推荐
Remember to use ternary expressions when switching transformations
求求你们,别再刷 Star 了!这跟“爱国”没关系!
Aptos教程-参与官方激励测试网(AIT2 激励测试网)
Please, stop painting star! This has nothing to do with patriotism!
Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline
matplotlib的安装教程以及简单调用
Aloam code reading and summary
Pychar modify pep8 e501 line too long > 0 characters
2020 Internet industry terminology
Steamos 3.3 beta release, steam deck Chinese keyboard finally came
paddlepaddle 28 搭建基于卷积的自动编码机
微信小程序视频分享平台系统毕业设计毕设(7)中期检查报告
Wechat nucleic acid detection appointment applet system graduation design completion (5) task statement
QT official example: QT quick controls - Gallery
vimium映射键
Typescript
Easyai notes - deep learning
Outsourcing for five years, abandoned
Picking up the camera is the best artistic healing
2020互联网行业术语