当前位置:网站首页>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;
}
}边栏推荐
猜你喜欢
随机推荐
Qt | 文件操作 QFile
uWSGI看这几篇就够了
防抖节流(后续继续更新)
无线振弦采集仪远程修改参数方式
Linux系统中mysql数据库的基本管理
2.3 - P、V、S机制
MySQL【数据类型】
2022 年值得尝试的 7 个 MQTT 客户端工具
Apache management and web optimization
System delay tasks and scheduled tasks
先睹为快!界面控件DevExpress WPF这些功能即将发布
Basic management of mysql database in Linux system
Eight big software attack overview of supply chain
类的比较大小(Comparable -> compareTo(类自己实现接口),Comparator -> compare(新建一个类作为比较器))
RecSys'22 推荐系统论文梳理
“行泊一体”的火爆与现实困境
ICML/ICLR'22 推荐系统论文梳理
Azure Kinect(K4A)人体识别跟踪进阶
禅道16.5升级17.3
WWW'22 推荐系统论文之序列推荐篇









