当前位置:网站首页>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;
}
}
边栏推荐
- 中英对照:You can do this. Best of luck祝你好运
- Redis core technology and basic architecture of actual combat: what does a key value database contain?
- CS-证书指纹修改
- [English] Verb Classification of grammatical reconstruction -- English rabbit learning notes (2)
- In English translation of papers, how to do a good translation?
- P5706 [deep foundation 2. Example 8] redistributing fat house water -- February 13, 2022
- 论文翻译英译中,怎样做翻译效果好?
- How much is the price for the seal of the certificate
- 一文读懂简单查询代价估算
- [Yu Yue education] Dunhuang Literature and art reference materials of Zhejiang Normal University
猜你喜欢
基于JEECG-BOOT的list页面的地址栏参数传递
钓鱼&文件名反转&office远程模板
ECS accessKey key disclosure and utilization
CS passed (cdn+ certificate) PowerShell online detailed version
[Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development
記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
How to convert flv file to MP4 file? A simple solution
翻译公司证件盖章的价格是多少
University of Manchester | dda3c: collaborative distributed deep reinforcement learning in swarm agent systems
Error getting a new connection Cause: org. apache. commons. dbcp. SQLNestedException
随机推荐
生物医学本地化翻译服务
金融德语翻译,北京专业的翻译公司
基于购买行为数据对超市顾客进行市场细分(RFM模型)
Successfully solved typeerror: data type 'category' not understood
PHP uses redis to implement distributed locks
如何做好互联网金融的英语翻译
JDBC requset corresponding content and function introduction
LeetCode每日一题(1997. First Day Where You Have Been in All the Rooms)
[unity] how to export FBX in untiy
Biomedical localization translation services
(practice C language every day) reverse linked list II
Redis Foundation
电子书-CHM-上线CS
LeetCode每日一题(1870. Minimum Speed to Arrive on Time)
LeetCode 732. My schedule III
Luogu p2089 roast chicken
Day 248/300 thoughts on how graduates find jobs
LeetCode 729. My schedule I
Luogu p2141 abacus mental arithmetic test
Cannot create poolableconnectionfactory (could not create connection to database server. error