当前位置:网站首页>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;
}
};
边栏推荐
- Wechat applet video sharing platform system graduation design completion (5) assignment
- vimium映射鍵
- 能解决80%故障的排查思路
- WPS inserts a picture and displays it completely
- SteamOS 3.3 Beta 发布,Steam Deck 中文键盘终于来了
- Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名
- 详解Kubernetes网络模型
- 微信小程序视频分享平台系统毕业设计毕设(5)任务书
- Interview, about thread pool
- 好评率计算
猜你喜欢
Easyai notes - machine learning
QT official example: QT quick controls - Gallery
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
MySQL -- basic concept of database
[games101] operation 4 B é zier curve
MySQL advanced - transaction and index
【愚公系列】2022年07月 Go教学课程 001-Go语言前提简介
Wechat applet video sharing platform system graduation design (3) background function
Summary of fun free GM games
Editor Editor Extension add button and logo in scene view
随机推荐
A4988与42步进电机
Troubleshooting ideas that can solve 80% of faults
毕业总结
Interview, about thread pool
Wechat nucleic acid detection and appointment applet system graduation design (3) background function
719. Find the distance of the number pair with the smallest K
MySQL进阶-事务及索引
ESP32-C3入门教程 问题篇⑩——error: implicit declaration of function ‘esp_blufi_close‘;
Develop a controller that prohibits deleting namespaces
微信核酸检测预约小程序系统毕业设计毕设(5)任务书
Unified interface for reading and writing data files in xml/json/ini and ubjson formats
Graduation summary
国金证券是国企吗?在国金证券开户资金安全吗?
vimium映射键
pycharm 修改 pep8 E501 line too long > 0 characters
Explain kubernetes network model in detail
拿起相机,便是最好的艺术疗愈
Remember to use ternary expressions when switching transformations
再放宽!这些应届生,可直接落户上海
Wechat applet video sharing platform system graduation design completion (5) assignment