当前位置:网站首页>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 程序员是不是也有“文人相轻”的毛病
边栏推荐
- The JSON format of the international area code of the mobile phone number is obtained with PHP
- 2022电工杯A题高比例风电电力系统储能运行及配置分析思路
- Antd Comment 递归循环评论
- Operational amplifier application summary 1
- In cooperation with the research team of the clinical trial center of the University of Hong Kong and Hong Kong Gangyi hospital, Kexing launched the clinical trial of Omicron specific inactivated vacc
- Redis源码学习(30),字典学习,dict.h
- Food Chem | in depth learning accurately predicts food categories and nutritional components based on ingredient statements
- POJ training plan 2253_ Frogger (shortest /floyd)
- [ArcGIS tutorial] thematic map production - population density distribution map - population density analysis
- NoSQL之Redis配置与优化
猜你喜欢
Web service performance monitoring scheme
Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
1.19.11.SQL客户端、启动SQL客户端、执行SQL查询、环境配置文件、重启策略、自定义函数(User-defined Functions)、构造函数参数
Why does WordPress open so slowly?
数据的存储
Antd comment recursive loop comment
Kotlin Android environment construction
NFT meta universe chain diversified ecosystem development case
ABAP 動態內錶分組循環
2022中青杯C题城市交通思路分析
随机推荐
Do you choose pandas or SQL for the top 1 of data analysis in your mind?
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
使用 BR 恢复 GCS 上的备份数据
史上最全MongoDB之部署篇
Using thread class and runnable interface to realize the difference between multithreading
机械臂速成小指南(十):可达工作空间
buildroot的根文件系统提示“depmod:applt not found”
二叉搜索树的实现
True global ventures' newly established $146million follow-up fund was closed, of which the general partner subscribed $62million to invest in Web3 winners in the later stage
How do test / development programmers get promoted? From nothing, from thin to thick
Different meat customers joined hands with Dexter to launch different hamburgers in some stores across the country
Hangzhou Electric 3711 binary number
pyqt5 失焦 监听无操作 定时器
[system management] clear the icon cache of deleted programs in the taskbar
Quick completion guide of manipulator (10): accessible workspace
ABAP 動態內錶分組循環
Implementation of binary search tree
Unity3d can change colors and display samples in a building GL material
The JSON format of the international area code of the mobile phone number is obtained with PHP
Some common software related