当前位置:网站首页>【英雄哥七月集训】第 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;
}
}
总结
边栏推荐
- 30. Learn highcharts label rotation histogram
- Study - Summary of geometric calculations
- Uncaught Error:Invalid geoJson format Cannot read property ‘length‘ of undefind
- A 58 year old native of Anhui Province, he has become the largest IPO investor in Switzerland this year
- Capture video by buffering
- C#流程控制语句
- 【Bluetooth蓝牙开发】八、BLE协议之传输层
- ABB electromagnetic flowmeter maintenance signal transmitter maintenance 41f/e4 technical parameters
- 职场高薪 |「中高级测试」面试题
- ICML2022 | 时序自监督视频transformer
猜你喜欢

Moco V1: the visual field can also be self supervised

程序员最大的浪漫~

Database -- use of explain

Ctfshow network lost track record (2)

Study and use of cobalt strike

Several skills of API interface optimization

证券企业基于容器化 PaaS 平台的 DevOps 规划建设 29 个典型问题总结

BUUCTF做题Upload-Labs记录pass-01~pass-10

Coding with these 16 naming rules can save you more than half of your comments!

quii cordova-plugin-telerik-imagepicker插件多图上传乱序
随机推荐
A 58 year old native of Anhui Province, he has become the largest IPO investor in Switzerland this year
实习日记第一周
Reading and writing basic data types in protobuf
在子组件中使用el-date-picker报错
High salary in the workplace | "intermediate and advanced test" interview questions
Guo Mingxuan: meta contraction is conducive to the development of VR competitors, and apple XR headshow will change the industry rules
怎么理解数据网格(Data Mesh)
SSM-使用@Async和创建ThreadPoolTaskExecutor线程池
System integration under microservice architecture
[Zhou Zhou has a prize] cloud native programming challenge "edge container" track invites you to fight!
顶级“Redis 笔记”, 缓存雪崩 + 击穿 + 穿透 + 集群 + 分布式锁,NB 了
Icml2022 | timing self-monitoring video transformer
Maxwell is an easy-to-use software for capturing MySQL data in real time
30. Learn highcharts label rotation histogram
探讨:想要落地DevOps的话,只考虑好的PaaS容器平台就够了么?
Ctfshow network lost track record (2)
职场高薪 |「中高级测试」面试题
Moco V1: the visual field can also be self supervised
There have been two safety accidents in a month after listing. Is L9 ideal?
向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!