当前位置:网站首页>剑指 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;
}
}
边栏推荐
- Deep learning: a solution to over fitting in deep neural networks
- Learn about servlets
- This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
- MySQL约束与多表查询实例分析
- C language 3-7 daffodils (enhanced version)
- Bat Android Engineer interview process analysis + restore the most authentic and complete first-line company interview questions
- 三分钟学会基础k线图知识
- MySQL主从延迟问题怎么解决
- MPLS experiment operation
- np.where 和 torch.where 用法
猜你喜欢

321. Chessboard segmentation (2D interval DP)

Selection of field types for creating tables in MySQL database

Learn basic K-line diagram knowledge in three minutes

This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable

Medical management system (C language course for freshmen)

The smart Park "ZhongGuanCun No.1" subverts your understanding of the park

卷積神經網絡(包含代碼與相應圖解)

医药管理系统(大一下C语言课设)

并发编程的三大核心问题

开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
随机推荐
This is the form of the K-line diagram (pithy formula)
Construction and maintenance of business websites [12]
D discard the virtual recovery method
开发那些事儿:如何利用Go单例模式保障流媒体高并发的安全性?
【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
Word search applet design report based on cloud development +ppt+ project source code + demonstration video
Ks006 student achievement management system based on SSM
基于SSM实现微博系统
Volume compression, decompression
Post infiltration flow encryption
Should enterprises choose server free computing?
Medical management system (C language course for freshmen)
There are spaces in the for loop variable in the shell -- IFS variable
Is the knowledge of University useless and outdated?
JMeter (I) - download, installation and plug-in management
What are the necessary things for students to start school? Ranking list of Bluetooth headsets with good sound quality
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
Learn basic K-line diagram knowledge in three minutes
Implementation principle of city selector component
I Brief introduction of radio energy transmission technology