当前位置:网站首页>55. maximum sum of continuous subarrays
55. maximum sum of continuous subarrays
2022-06-28 16:59:00 【hys__ handsome】
Record the standard schedule of classic questions .
Ideas
Greedy practices : Add a number first , If it is less than 0 Just directly remake. Because there's no need to put negative numbers first , It would be better to get rid of it .
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int res = -0x3f3f3f3f, sum = 0;
for(int i = 0,tmp = 0; i < nums.size(); i++){
sum += nums[i];
res = max(res,sum);
if(sum < 0) sum = 0;
// If nums All negative numbers return the largest negative number
}
return res;
}
};
dp Strategy .
边栏推荐
猜你喜欢
基于DataWorks的时效仿真平台|得物技术
Practice of curve replacing CEPH in Netease cloud music
浅谈 SAP 软件里的价格折扣设计原理
visio 使用
10.Hystrix断路器
NOIP普及组2006-2018初赛 2019 CSP-J1 2020 CSP-J1 完善程序题
【TcaplusDB知识库】TcaplusDB技术支持介绍
使用Karmada实现Helm应用的跨集群部署
这个简单的小功能,半年为我们产研团队省下213个小时
You have a chance to collect wool. Click "earn" and you will have a chance to earn a high commission
随机推荐
Coding Devops helps Sinochem information to build a new generation of research efficiency platform and drive the new future of "online Sinochem"
2019 CSP J2 entry group csp-s2 improvement group round 2 video and question solution
【Hot100】2. Add two numbers
Five solutions that give consideration to enterprise anti epidemic and development, from IBM
7-用户输入和while循环
使用Karmada实现Helm应用的跨集群部署
如何备份 WordPress 数据库
[tcaplusdb knowledge base] view tcapdir directory server
Noip1998-2018 csp-s2 2019 2021 improvement group problem solving report and video
This simple little function saves 213 hours for our production research team in half a year
解决sqoop出现 ERROR manager.SqlManager: Generic SqlManager.listDatabases() not implemented
What you have to know under the digital collection boom
LDD knowledge sorting
Yesterday, metauniverse | Wal Mart set up an innovation department to explore metauniverse and Web3, and Dior released the metauniverse Exhibition
Yesterday, yuancosmos | meta's "yuancosmos" Department lost $2.96 billion in the first quarter, and Liufu jewelry issued Digital Collections
GCC efficient graph revolution for joint node representationlearning and clustering
浅谈 SAP 软件里的价格折扣设计原理
Use open connector to integrate hubspot and SAP systems
PotPlayer播放百度雲盤視頻
FS2K人脸素描属性识别