当前位置:网站首页>Leetcode - 152 product maximum subarray
Leetcode - 152 product maximum subarray
2022-07-06 06:40:00 【Cute at the age of three @d】
Dynamic programming
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;
}
}
边栏推荐
- 我的创作纪念日
- [English] Verb Classification of grammatical reconstruction -- English rabbit learning notes (2)
- Lesson 7 tensorflow realizes convolutional neural network
- 查询字段个数
- 基于购买行为数据对超市顾客进行市场细分(RFM模型)
- 如何做好金融文献翻译?
- Introduction and underlying analysis of regular expressions
- [ 英语 ] 语法重塑 之 动词分类 —— 英语兔学习笔记(2)
- Suspended else
- 英语论文翻译成中文字数变化
猜你喜欢
How to translate biomedical instructions in English
LeetCode每日一题(971. Flip Binary Tree To Match Preorder Traversal)
LeetCode - 152 乘积最大子数组
Drug disease association prediction based on multi-scale heterogeneous network topology information and multiple attributes
LeetCode 731. My schedule II
如何做好互联网金融的英语翻译
LeetCode 732. My schedule III
MySQL5.72.msi安装失败
ECS accessKey key disclosure and utilization
MySQL is sorted alphabetically
随机推荐
PHP uses redis to implement distributed locks
如何做好互联网金融的英语翻译
CS-证书指纹修改
Financial German translation, a professional translation company in Beijing
基于JEECG-BOOT的list页面的地址栏参数传递
Classification des verbes reconstruits grammaticalement - - English Rabbit Learning notes (2)
Basic knowledge of MySQL
基於JEECG-BOOT的list頁面的地址欄參數傳遞
Biomedical localization translation services
LeetCode 739. Daily temperature
利用快捷方式-LNK-上线CS
基于购买行为数据对超市顾客进行市场细分(RFM模型)
The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
My seven years with NLP
How to convert flv file to MP4 file? A simple solution
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Esp32 esp-idf watchdog twdt
查询字段个数
How much is it to translate Chinese into English for one minute?
LeetCode - 152 乘积最大子数组