当前位置:网站首页>LeetCode - 152 乘积最大子数组
LeetCode - 152 乘积最大子数组
2022-07-06 06:28:00 【三岁就很萌@D】
动态规划
class Solution {
public int maxProduct(int[] nums) {
int n = nums.length;
int maxv = 1;
int minv = 1;
int ans = Integer.MIN_VALUE;
for(int i = 0;i < n;i++){
int premax = maxv;
int premin = minv;
if(nums[i] < 0){
maxv = Math.max(premin*nums[i],nums[i]);
minv = Math.min(premax*nums[i],nums[i]);
}
else{
maxv = Math.max(premax*nums[i],nums[i]);
minv = Math.min(premin*nums[i],nums[i]);
}
ans = Math.max(maxv,ans);
}
return ans;
}
}
边栏推荐
- 在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)
- 記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
- Error getting a new connection Cause: org. apache. commons. dbcp. SQLNestedException
- Modify the list page on the basis of jeecg boot code generation (combined with customized components)
- LeetCode 732. My schedule III
- mysql的基础命令
- 字幕翻译中翻英一分钟多少钱?
- Cobalt strike feature modification
- 翻译影视剧字幕,这些特点务必要了解
- Qt:无法定位程序输入点XXXXX于动态链接库。
猜你喜欢
Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
Transfert des paramètres de la barre d'adresse de la page de liste basée sur jeecg - boot
Postman core function analysis - parameterization and test report
Private cloud disk deployment
如何做好金融文献翻译?
MFC on the conversion and display of long string unsigned char and CString
关于新冠疫情,常用的英文单词、语句有哪些?
org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
ECS accessKey key disclosure and utilization
红蓝对抗之流量加密(Openssl加密传输、MSF流量加密、CS修改profile进行流量加密)
随机推荐
mysql按照首字母排序
[ 英语 ] 语法重塑 之 动词分类 —— 英语兔学习笔记(2)
Postman core function analysis - parameterization and test report
如何将flv文件转为mp4文件?一个简单的解决办法
Today's summer solstice
论文摘要翻译,多语言纯人工翻译
leetcode 24. Exchange the nodes in the linked list in pairs
In English translation of papers, how to do a good translation?
MySQL5.72.msi安装失败
[ 英语 ] 语法重塑 之 英语学习的核心框架 —— 英语兔学习笔记(1)
私人云盘部署
Office-DOC加载宏-上线CS
国际经贸合同翻译 中译英怎样效果好
翻译影视剧字幕,这些特点务必要了解
What are the characteristics of trademark translation and how to translate it?
Is the test cycle compressed? Teach you 9 ways to deal with it
How do programmers remember code and programming language?
CS passed (cdn+ certificate) PowerShell online detailed version
Grouping convolution and DW convolution, residuals and inverted residuals, bottleneck and linearbottleneck
Advanced MySQL: Basics (1-4 Lectures)