当前位置:网站首页>Sword finger offer 42 Maximum sum of successive subarrays
Sword finger offer 42 Maximum sum of successive subarrays
2022-06-24 22:56:00 【I'm not xiaohaiwa~~~~】
Enter an integer array , One or more consecutive integers in an array form a subarray . Find the maximum sum of all subarrays . The required time complexity is O(n).
Example 1:
Input : nums = [-2,1,-3,4,-1,2,1,-5,4]
Output : 6
explain : Continuous subarray [4,-1,2,1] And the biggest , by 6.
Tips :
- 1 <= arr.length <= 10^5
- -100 <= arr[i] <= 100
Code:
int maxSubArray(vector<int>& nums)
{
int maxnum=nums[0];
int sum=0;
for(int i=0;i<nums.size();i++)
{
sum=max(sum+nums[i],nums[i]);
maxnum=max(maxnum,sum);
}
cout<<maxnum<<endl;
return maxnum;
}
边栏推荐
- Leetcode algorithm The first common node of two linked lists
- [personal experiment report]
- It's hard to hear C language? Why don't you take a look at my article (7) input and output
- Introduction to machine learning compilation course learning notes lesson 1 overview of machine learning compilation
- The difference between interceptor and filter
- Programmers become gods by digging holes in one year, carrying flags in five years and becoming gods in ten years
- [WSL] SSH Remote Connection and host port forwarding configuration
- 2022年高处安装、维护、拆除考试模拟100题及模拟考试
- C language operators and expressions
- Annotation
猜你喜欢

Chapter 10 project stakeholder management

Win10 or win11 printer cannot print

The core concept of JMM: happens before principle

机器学习编译入门课程学习笔记第一讲 机器学习编译概述

结合源码剖析Oauth2分布式认证与授权的实现流程

加分利器 不负所托 | 知道创宇获攻防演练防守方感谢信!

【文本数据挖掘】中文命名实体识别:HMM模型+BiLSTM_CRF模型(Pytorch)【调研与实验分析】

Principles of Ethernet port mirroring, link aggregation and VLAN Technology

canvas 实现图片新增水印

【Mongodb】READ_ME_TO_RECOVER_YOUR_DATA,数据库被恶意删除
随机推荐
Solution to the login error of tangdou people
Research Report on market supply and demand and strategy of ceiling power supply device industry in China
【ROS玩转Turtlesim小海龟】
Idea global search replace shortcut key
2022-06-10 work record --js- obtain the date n days after a certain date
MySQL + JSON = King fried!!
Feign project construction
Wechat side: what is consistent hash? In what scenario? What problems have been solved?
Row and column differences in matrix construction of DX HLSL and GL glsl
The usage difference between isempty and isblank is so different that so many people can't answer it
【软件工程】期末重点
关于某手滑块的一些更新(6-18,js逆向)
Heavyweight! Fada is listed as a "specialized and new" enterprise
使用Aggregated APIServer扩展你的kubernetes API
See how sparksql supports enterprise data warehouse
find your present (2)
EPICS记录参考2--EPICS过程数据库概念
Unable to use the bean introduced into the jar package
Web security XSS foundation 06
Research Report on research and investment prospects of China's container coating industry (2022 Edition)