当前位置:网站首页>【英雄哥七月集训】第 28天:动态规划
【英雄哥七月集训】第 28天:动态规划
2022-07-28 19:41:00 【如果我是温帅帅】
一、53. 最大子数组和
给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
子数组 是数组中的一个连续部分。
leetcode 53 java
思路
动态规划 dp[i]+=dp[i-1] (dp[i-1]>0)
class Solution {
public int maxSubArray(int[] nums) {
int n = nums.length;
int[] dp = new int[n];
for(int i = 0; i<n ;i++){
dp[i] = nums[i];
if(i>0 && dp[i-1]>0){
dp[i]+=dp[i-1];
}
}
int max = -10010;
for(int i = 0; i<n ;i++){
max = Math.max(max,dp[i]);
}
return max;
}
}
总结
边栏推荐
- 广和通&高通物联网技术开放日成功举办
- The development of smart home industry pays close attention to edge computing and applet container technology
- Go并发编程基础
- Redis cache avalanche, cache penetration, cache breakdown
- 属性基加密仿真及代码实现(CP-ABE)论文:Ciphertext-Policy Attribute-Based Encryption
- 4.2 Virtual Member Functions
- ctfshow 网络迷踪做题记录(2)
- Kubeadm搭建kubernetes集群
- DLL decompile (decompile encrypted DLL)
- Link with Bracket Sequence I(状态基多维dp)
猜你喜欢

Color finder actual combat (QT including source code)

Another installation artifact

(PMIC) full and half bridge drive csd95481rwj PDF specification

Backup and recovery of SQL Server database

实现瀑布流效果

Moco V1: the visual field can also be self supervised

【TiDB】txt文档导入数据库,这样做真的很高效

Maintenance of delta hot metal detector principle analysis of v5g-jc-r1 laser measurement sensor / detector

Redis cache avalanche, cache penetration, cache breakdown

ICML2022 | 时序自监督视频transformer
随机推荐
[tidb] importing TXT documents into the database is really efficient
Ijcai2022 tutorial | dialogue recommendation system
Moco V2: further upgrade of Moco series
牛客打开摄像头几秒后画面消失 | 相机打开画面一闪一闪
百度搜索符合预期,但涉及外链黑帽策略,什么原因?
Deit: attention can also be distilled
Uncaught Error:Invalid geoJson format Cannot read property ‘length‘ of undefind
上市1个月接连发生两起安全事故,理想L9还理想吗?
职场高薪 |「中高级测试」面试题
学习Typescript(二)
4.1 Member的各种调用方式
Attribute based encryption simulation and code implementation (cp-abe) paper: ciphertext policy attribute based encryption
详细讲解C语言12(C语言系列)
Redis cache avalanche, cache penetration, cache breakdown
1162. 地图分析-非递归法
Study - 几何计算总结
Efficientformer: lightweight vit backbone
ABB电磁流量计维修信号变送器维修41F/E4技术参数
Several skills of API interface optimization
Quii Cordova plugin telerik imagepicker plug-in multi image upload out of sequence