当前位置:网站首页>JZ42 连续子数组的最大和
JZ42 连续子数组的最大和
2022-08-02 15:35:00 【syc596】
JZ42 连续子数组的最大和
连续子数组的最大和_牛客题霸_牛客网 (nowcoder.com)
// //贪心
// public class Solution {
// public int FindGreatestSumOfSubArray(int[] array){
// int sum=array[0];
// int max=array[0];
// for(int i=1;i<array.length;i++){
// sum=Math.max(sum+array[i],array[i]);
// if(sum>max){
// max=sum;
// }
// }
// return max;
// }
// }
//动规
public class Solution {
public int FindGreatestSumOfSubArray(int[] array){
int[] dp=new int[array.length];
dp[0]=array[0];
int max=array[0];
for(int i=1;i<array.length;i++){
dp[i]=Math.max(dp[i-1]+array[i],array[i]);
if(dp[i]>max){
max=dp[i];
}
}
return max;
}
}边栏推荐
猜你喜欢

UnicodeEncodeError: 'gbk' codec can't encode character '\u2022' in position 178: illegal multibyte s

亏损扩大/毛利偏低,北斗智联与「智能座舱第一阵营」的不等号

类的比较大小(Comparable -> compareTo(类自己实现接口),Comparator -> compare(新建一个类作为比较器))

MySQL-1-环境部署

esp32之arduino配置下载提速

CefSharp实战演示

dogs vs cats 二分类问题vgg16迁移学习

Thinkpad E430c使用u盘安装系统

制胜精细化运营时代 华为应用市场打出内容、场景、商业运营组合拳

面试官:可以谈谈乐观锁和悲观锁吗
随机推荐
JZ32 从上往下打印二叉树
System delay tasks and scheduled tasks
tiup mirror rotate
redis学习四redis消息订阅、pipeline、事务、modules、布隆过滤器、缓存LRU
Linux系统中mysql数据库的基本管理
入门关于 switch case 的理解
ICML/ICLR'22 推荐系统论文梳理
ROS 之 KUKA iiwa编程
2.7 - 文件管理 2.8 - 多级目录结构 2.9 - 位示图
WWW'22 推荐系统论文之序列推荐篇
AI智能剪辑,仅需2秒一键提取精彩片段
Apache的管理及web优化
【wpf】ListView 和 ItemsControl 的一点区别
DC-DC选型及电路设计
从特征交互到数据交互,浅谈深度点击率模型的新趋势
IJCAI'22 推荐系统论文梳理
CefSharp实战演示
Idea中运行sparkSQL
JZ15 二进制中1的个数
MySQL-3-密码破解