当前位置:网站首页>Leetcode sword finger offer jz42 maximum sum of continuous subarrays
Leetcode sword finger offer jz42 maximum sum of continuous subarrays
2022-07-24 06:25:00 【Happy and at ease】
The author comes up with two kinds of questions Problem solving mode
The first solution to violence , Traversing arrays directly array Sequentially calculate a[1] Value a[1]+a[2] Value a[1]+a[2]+a[3] Value
Deduce in sequence Values of various continuous subarrays , And then in turn max Value comparison .
The second one adopts the idea of dynamic programming
class Solution {
public:
int FindGreatestSumOfSubArray(vector<int> array) {
int cursum=0; //cursum Is before the sequence number of the current array Maximum value of continuous word array
int ret=array[0];//ret Is the first string of the current array
for(int i=0;i<array.size();i++) // Traversal array array
{
if(cursum<=0)
cursum=array[i]; // The maximum value before the sequence number of the current array is less than zero , Then the maximum value of the current serial number will not exceed the current value
else
cursum+=array[i];
ret=max(ret,cursum);// Keep going cursum Compare the values of , Call out the big one and put it in ret;
}
return ret;
}
};边栏推荐
- Top 10 vulnerability assessment and penetration testing tools
- Do not rent a server, build your own personal business website (how to buy a domain name)
- IP笔记(11)
- [no need for public IP] configure a fixed public TCP port address for remote desktop raspberry pie
- Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]
- 常见十大漏洞总结(原理、危害、防御)
- Hololens 2 development: development environment deployment
- A batch of interview questions and answers_ 20180403 latest arrangement
- Dameng database_ Various methods of connecting databases and executing SQL and scripts under disql
- Jenkins automated unattended operation (up / down)
猜你喜欢

Do not rent a server, build your own personal business website (how to buy a domain name)

The public network uses Microsoft Remote Desktop remote desktop to work remotely at any time

IP笔记(9)

MySQL从基础到入门到高可用

如何建立一个仪式感点满的网站,并发布到公网 2-2

IP课笔记(5)

A batch of interview questions and answers_ 20180403 latest arrangement

【222】内存溢出及定位

UE4: what is the gameplay framework

IP课(OSPF)综合实验
随机推荐
Solutions to the failure of wechat TBS online kernel installation
Understanding of Flink parallelism
IP job (1)
Summary of common working methods (7S, SWOT analysis, PDCA cycle, smart principle, 6w2h, time management, WBS, 28 principles)
[226] instructions for Wireshark parameters
IP notes (11)
公网访问内网IIS网站服务器【无需公网IP】
[301] grotesque behavior - predictable irrationality
UE4 replacement system 3. Final results
UE4 reload system 2. Scene capture of reload system
Remote connection to Qunhui NAS at home [no public IP, free intranet penetration]
简单三步快速实现内网穿透
Configure a fixed remote desktop address [intranet penetration, no need for public IP]
【222】内存溢出及定位
The public network uses Microsoft Remote Desktop remote desktop to work remotely at any time
常见十大漏洞总结(原理、危害、防御)
How to build a website full of ritual sense and publish it on the public website 2-2
Unity shader migrated from built-in rendering pipeline to URP
MySQL数据库—SQL汇总(记得关注我!中国加油!)
Machine learning & deep learning introduction information sharing summary