当前位置:网站首页>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;
}
};
边栏推荐
- 719. Find the distance of the number pair with the smallest K
- Wasserstein slim gain with clipping penalty (wsgain-cp) introduction and code implementation -- missing data filling based on generating countermeasure network
- 微信核酸检测预约小程序系统毕业设计毕设(2)小程序功能
- Simple understanding of cardinality sorting
- Please, stop painting star! This has nothing to do with patriotism!
- 微信核酸检测预约小程序系统毕业设计毕设(3)后台功能
- [Northwestern Polytechnic University] information sharing of the first and second postgraduate examinations
- A4988与42步进电机
- QQmlApplicationEngine
- [games101] operation 4 B é zier curve
猜你喜欢

Détends - toi encore! Ces nouveaux étudiants peuvent s'installer directement à Shanghai

微信核酸检测预约小程序系统毕业设计毕设(5)任务书

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

微信小程序视频分享平台系统毕业设计毕设(2)小程序功能

Embedded ~ introduction

Steamos 3.3 beta release, steam deck Chinese keyboard finally came

拿起相机,便是最好的艺术疗愈

微信小程序视频分享平台系统毕业设计毕设(7)中期检查报告

RDK仿真实验

Leetcode 面试题 17.04. 消失的数字
随机推荐
Leetcode 面试题 17.04. 消失的数字
In Linux, MySQL sets the job task to start automatically
C# 检测图片是否被旋转并修改到正真的旋转
win10 kms activator
D constructor problem
好玩的免费GM游戏整理汇总
Yingguang MCU development case
Pychar modify pep8 e501 line too long > 0 characters
Embedded development board ~ description
Design of the multi live architecture in different places of the king glory mall
paddlepaddle 28 搭建基于卷积的自动编码机
Intelligent hydropower meter energy consumption monitoring cloud platform
Editor Editor Extension add button and logo in scene view
Tower safety monitoring system unattended inclination vibration monitoring system
微信小程序视频分享平台系统毕业设计毕设(6)开题答辩PPT
Iframe nesting details
Wechat nucleic acid detection and appointment applet system graduation design (3) background function
Esp32-c3 introductory tutorial question ⑩ - error: implicit declaration of function 'ESP_ blufi_ close‘;
饭卡 HDU2546
win10 卸载cuda