当前位置:网站首页>leetcode 53. Maximum Subarray 最大子数组和(中等)
leetcode 53. Maximum Subarray 最大子数组和(中等)
2022-07-06 21:44:00 【InfoQ】
一、题目大意
- 1 <= nums.length <= 105
- -104 <= nums[i] <= 104
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public int maxSubArray(int[] nums) {
int n = nums.length;
int[] dp = new int[n];
dp[0] = nums[0];
int max = dp[0];
for (int i = 1; i < n; i++) {
dp[i] = Math.max(dp[i - 1] + nums[i], nums[i]);
max = Math.max(dp[i], max);
}
return max;
}
}
四、总结小记
- 2022/7/6 程序员是不是也有“文人相轻”的毛病
边栏推荐
- 别样肉客联手德克士在全国部分门店推出别样汉堡
- List interview common questions
- Hongmi K40S root gameplay notes
- Five years of automated testing, and finally into the ByteDance, the annual salary of 30W is not out of reach
- Formation continue en robotique (automatisation) - 2022 -
- 杭州电 3711 Binary Number
- 2022中青杯C题城市交通思路分析
- The most complete security certification of mongodb in history
- Golang compresses and decompresses zip files
- 2022 electrician cup question B analysis of emergency materials distribution under 5g network environment
猜你喜欢
[multi threading exercise] write a multi threading example of the producer consumer model.
Opencv third party Library
[hcie TAC] question 3
NoSQL之Redis配置与优化
idea gradle lombok 报错集锦
Create commonly used shortcut icons at the top of the ad interface (menu bar)
Ggplot facet detail adjustment summary
Ssm+jsp realizes enterprise management system (OA management system source code + database + document +ppt)
The most complete learning rate adjustment strategy in history LR_ scheduler
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
随机推荐
Allow public connections to local Ruby on Rails Development Server
The most complete learning rate adjustment strategy in history LR_ scheduler
leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
EasyUI export excel cannot download the method that the box pops up
Dab-detr: dynamic anchor boxes are better queries for Detr translation
ABAP dynamic inner table grouping cycle
Opencv third party Library
Mongo shell, the most complete mongodb in history
Highly paid programmers & interview questions. Are you familiar with the redis cluster principle of series 120? How to ensure the high availability of redis (Part 1)?
Some thoughts on cross end development of kbone and applet
[OA] excel document generator: openpyxl module
Why does WordPress open so slowly?
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
Unity3d can change colors and display samples in a building GL material
史上最全MongoDB之初识篇
golang 压缩和解压zip文件
【OA】Excel 文档生成器: Openpyxl 模块
Binary, octal, hexadecimal
PHP 实现根据概率抽奖
运算放大器应用汇总1