当前位置:网站首页>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;
}
边栏推荐
- 关于某手滑块的一些更新(6-18,js逆向)
- 【Mongodb】READ_ME_TO_RECOVER_YOUR_DATA,数据库被恶意删除
- The difference between interceptor and filter
- Learning bit segment (1)
- 【软件工程】期末重点
- Parental delegation mechanism
- 【个人实验报告】
- 中国SSD行业企业势力全景图
- Envoy obtain the real IP address of the client
- High level application of SQL statements in MySQL database (II)
猜你喜欢
How to solve the problem that the computer suddenly can't connect to WiFi

The core concept of JMM: happens before principle

Selection and comparison of message oriented middleware MQ

大厂面试必问:如何解决TCP可靠传输问题?8张图带你详细学习

Recommended course: workplace writing training

Future development of education industry of e-commerce Express

The usage difference between isempty and isblank is so different that so many people can't answer it

canvas 实现图片新增水印

【Mongodb】READ_ ME_ TO_ RECOVER_ YOUR_ Data, the database is deleted maliciously

Web security XSS foundation 06
随机推荐
糖豆人登录报错解决方案
【软件工程】期末重点
Extend your kubernetes API with aggregated apiserver
Future development of education industry of e-commerce Express
Vulnhub Vegeta: 1
Idea global search replace shortcut key
Unable to use the bean introduced into the jar package
China smallpox vaccine market trend report, technical innovation and market forecast
Learn more about the practical application of sentinel
MySQL夺命10问,你能坚持到第几问?
C#学习两年的增删改查和C#导入导出(去重)案例
双亲委派机制
Wechat side: what is consistent hash? In what scenario? What problems have been solved?
In the era of full programming, should I give up this road?
问题求解——嵌套列表
【Mongodb】READ_ME_TO_RECOVER_YOUR_DATA,数据库被恶意删除
EPICS记录参考4--所有输入记录都有的字段和所有输出记录都有的字段
EPICS记录参考2--EPICS过程数据库概念
2022-06-16 work record --js- judge the number of digits in string type digits + judge the number of digits in numeric type digits + limit the text length (display n words at most, exceeding...)
Row and column differences in matrix construction of DX HLSL and GL glsl