当前位置:网站首页>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;
}
};
边栏推荐
- 能解决80%故障的排查思路
- Typescript
- Nvidia 显卡 Failed to initialize NVML Driver/library version mismatch 错误解决方案
- 铁塔安全监测系统 无人值守倾角振动监测系统
- 27:第三章:开发通行证服务:10:【注册/登录】接口:注册/登录OK后,把用户会话信息(uid,utoken)保存到redis和cookie中;(一个主要的点:设置cookie)
- MySQL advanced - transaction and index
- exness深度好文:动性系列-黄金流动性实例分析(五)
- Web chat tool
- 微信核酸检测预约小程序系统毕业设计毕设(2)小程序功能
- Interview, about thread pool
猜你喜欢

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

微信小程序视频分享平台系统毕业设计毕设(1)开发概要

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

Nvidia 显卡 Failed to initialize NVML Driver/library version mismatch 错误解决方案

NVIDIA graphics card failed to initialize nvml driver/library version mismatch error solution

MySQL installation and configuration

MySQL安装与配置
![[games101] operation 4 B é zier curve](/img/57/e7a9191b959cb1177b7bd1a439df2a.png)
[games101] operation 4 B é zier curve

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

Wechat applet video sharing platform system graduation design (2) applet function
随机推荐
揭秘得物客服IM全链路通信过程
铁塔安全监测系统 无人值守倾角振动监测系统
In early summer, Kaiyuan magic changed an electric mosquito racket with killing sound effect!
Tower safety monitoring system unattended inclination vibration monitoring system
ESP32-C3入门教程 问题篇⑩——error: implicit declaration of function ‘esp_blufi_close‘;
Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名
实施阴影介绍
Wechat applet video sharing platform system graduation design completion (4) opening report
Qt官方示例:Qt Quick Controls - Gallery
微信核酸检测预约小程序系统毕业设计毕设(1)开发概要
自定义一个loading指令
Another double non reform exam 408, will it be cold? Software College of Nanchang Aviation University
Implementation shadow introduction
Leetcode 面试题 17.01. 不用加号的加法
微信小程序视频分享平台系统毕业设计毕设(7)中期检查报告
How can you omit a large number of switch statements
Editor编辑器扩展在Scene View添加按钮和logo
微信小程序视频分享平台系统毕业设计毕设(8)毕业设计论文模板
NVIDIA graphics card failed to initialize nvml driver/library version mismatch error solution
matplotlib的安装教程以及简单调用