当前位置:网站首页>Leetcode interview question 16.17 Continuous sequence
Leetcode interview question 16.17 Continuous sequence
2022-07-02 18:25:00 【I'm not Xiao Haiwa~~~~】
Given an array of integers , Find the sequence with the largest sum , And return the sum .
Example :
Input : [-2,1,-3,4,-1,2,1,-5,4]
Output : 6
explain : Continuous subarray [4,-1,2,1] And the biggest , by 6.
Advanced :
- If you have implemented complexity as O(n) Solution method , Try to use a more sophisticated divide and conquer method to solve .
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;
}
};
边栏推荐
- Unity学习shader笔记[八十二]增强单通道颜色渲染的黑白处理
- QT official example: QT quick controls - Gallery
- 719. Find the distance of the number pair with the smallest K
- 515. Find the maximum value in each tree row
- 977. Square of ordered array
- Graduation summary
- 实施阴影介绍
- Summary of fun free GM games
- paddlepaddle 28 搭建基于卷积的自动编码机
- 1288_FreeRTOS中vTaskResume()接口以及中断安全版本接口实现分析
猜你喜欢
Qt Official examples: Qt Quick Controls - Gallery
Editor Editor Extension add button and logo in scene view
Wechat applet video sharing platform system graduation design completion (1) development outline
[games101] operation 4 B é zier curve
NM01-独立于总线协议的NM模块功能概述与API定义
微信小程序视频分享平台系统毕业设计毕设(3)后台功能
Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline
【西北工业大学】考研初试复试资料分享
巴比特 | 元宇宙每日必读:一千块就能买一个虚拟主播?这是小企业的直播福音还是在“割韭菜”?...
Wechat nucleic acid detection and appointment applet system graduation design (3) background function
随机推荐
微信核酸检测预约小程序系统毕业设计毕设(2)小程序功能
UE4 用spline画正圆
em120.gige. h
Calculation of favorable comment rate
vimium映射鍵
2020互联网行业术语
719. Find the distance of the number pair with the smallest K
RTE11- 中断解耦功能
A good programmer is worth five ordinary programmers!
微信小程序视频分享平台系统毕业设计毕设(7)中期检查报告
微信核酸检测预约小程序系统毕业设计毕设(4)开题报告
Unity learning shader notes [82] black and white processing of enhanced single channel color rendering
Editor Editor Extension add button and logo in scene view
Wechat nucleic acid detection and appointment applet system graduation design (3) background function
Détends - toi encore! Ces nouveaux étudiants peuvent s'installer directement à Shanghai
1288_FreeRTOS中vTaskResume()接口以及中断安全版本接口实现分析
Steamos 3.3 beta release, steam deck Chinese keyboard finally came
WPS inserts a picture and displays it completely
719. 找出第 K 小的数对距离
Wechat applet video sharing platform system graduation design (3) background function