当前位置:网站首页>剑指 Offer 42. 连续子数组的最大和
剑指 Offer 42. 连续子数组的最大和
2022-07-02 01:54:00 【Yake1965】
剑指 Offer 42. 连续子数组的最大和
class Solution {
public int maxSubArray(int[] nums) {
int pre = -100, ans = nums[0];
for(int x : nums){
pre = pre < 0 ? x : pre + x; // 和为负数时从新开始
if(pre > ans) ans = pre;
}
return ans;
}
}
边栏推荐
- Word search applet design report based on cloud development +ppt+ project source code + demonstration video
- Cross domain? Homology? Understand what is cross domain at once
- Learn about servlets
- Deep learning: a solution to over fitting in deep neural networks
- ES6 new method of string
- This is the form of the K-line diagram (pithy formula)
- C language 3-7 daffodils (enhanced version)
- JMeter (I) - download, installation and plug-in management
- II Basic structure of radio energy transmission system
- 医药管理系统(大一下C语言课设)
猜你喜欢
企业应该选择无服务器计算吗?
Matlab uses resample to complete resampling
New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port
Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)
Learn about servlets
Architecture evolution from MVC to DDD
机器学习基本概念
成功实现边缘编码需要了解的六大经验教训
Memorabilia of domestic database in June 2022
1069. Division of convex polygons (thinking, interval DP)
随机推荐
MySQL约束与多表查询实例分析
MySQL如何解决delete大量数据后空间不释放的问题
Bat Android Engineer interview process analysis + restore the most authentic and complete first-line company interview questions
SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5
JMeter (II) - install the custom thread groups plug-in
Makefile simple induction
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
Introduction to ffmpeg Lib
Number of palindromes in C language (leetcode)
Deep learning: a solution to over fitting in deep neural networks
1069. Division of convex polygons (thinking, interval DP)
Quatre stratégies de base pour migrer la charge de travail de l'informatique en nuage
matlab 实现语音信号重采样和归一化,并播放比对效果
分卷压缩,解压
VARIATIONAL IMAGE COMPRESSION WITH A SCALE HYPERPRIOR文献实验复现
mysql列转行函数指的是什么
Three core problems of concurrent programming
Experimental reproduction of variable image compression with a scale hyperprior
Medical management system (C language course for freshmen)
Android: the kotlin language uses grendao3, a cross platform app development framework