当前位置:网站首页>Sword finger offer 42 Maximum sum of continuous subarrays
Sword finger offer 42 Maximum sum of continuous subarrays
2022-07-02 02:00:00 【Yake1965】
The finger of the sword Offer 42. The maximum sum of successive subarrays
class Solution {
public int maxSubArray(int[] nums) {
int pre = -100, ans = nums[0];
for(int x : nums){
pre = pre < 0 ? x : pre + x; // Start again when sum is negative
if(pre > ans) ans = pre;
}
return ans;
}
}
边栏推荐
- Discussion on the idea of platform construction
- Quatre stratégies de base pour migrer la charge de travail de l'informatique en nuage
- 电子协会 C语言 1级 32、计算2的幂
- leetcode2312. Selling wood blocks (difficult, weekly race)
- STM32F103——两路PWM控制电机
- 剑指 Offer 42. 连续子数组的最大和
- D discard the virtual recovery method
- leetcode2311. 小于等于 K 的最长二进制子序列(中等,周赛)
- Regular expression learning notes
- "C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure
猜你喜欢
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
Implementation of Weibo system based on SSM
How to use redis ordered collection
leetcode373. 查找和最小的 K 对数字(中等)
How to execute an SQL in MySQL
分卷压缩,解压
【毕业季】研究生学长分享怎样让本科更有意义
Matlab uses audioread and sound to read and play WAV files
Redis环境搭建和使用的方法
随机推荐
MySQL constraints and multi table query example analysis
遷移雲計算工作負載的四個基本策略
There are spaces in the for loop variable in the shell -- IFS variable
牛客网——华为题库(51~60)
Open那啥的搭建文档
Construction and maintenance of business websites [15]
How to build and use redis environment
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
leetcode2305. 公平分发饼干(中等,周赛,状压dp)
D discard the virtual recovery method
The concept, function, characteristics, creation and deletion of MySQL constraints
Openssl3.0 learning XXI provider encoder
Makefile simple induction
leetcode373. Find and minimum k-pair numbers (medium)
Ks006 student achievement management system based on SSM
Exception handling of class C in yyds dry goods inventory
Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound
剑指 Offer II 031. 最近最少使用缓存
Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months
正则表达式学习笔记