当前位置:网站首页>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;
}
}
边栏推荐
- Engineering organisms containing artificial metalloenzymes perform unnatural biosynthesis
- 生物医学英文合同翻译,关于词汇翻译的特点
- Luogu p2141 abacus mental arithmetic test
- mysql的基础命令
- Cobalt strike feature modification
- It is necessary to understand these characteristics in translating subtitles of film and television dramas
- Classification des verbes reconstruits grammaticalement - - English Rabbit Learning notes (2)
- Error getting a new connection Cause: org. apache. commons. dbcp. SQLNestedException
- [unity] how to export FBX in untiy
- Distributed system basic (V) protocol (I)
猜你喜欢
ECS accessKey key disclosure and utilization
Drug disease association prediction based on multi-scale heterogeneous network topology information and multiple attributes
Apple has open source, but what about it?
翻译生物医学说明书,英译中怎样效果佳
Office-DOC加载宏-上线CS
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用Shap值对XGBoost模型实现可解释性案例之详细攻略
Introduction and underlying analysis of regular expressions
关于新冠疫情,常用的英文单词、语句有哪些?
Modify the list page on the basis of jeecg boot code generation (combined with customized components)
端午节快乐Wish Dragon Boat Festival is happy
随机推荐
記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
成功解决TypeError: data type ‘category‘ not understood
LeetCode 739. Daily temperature
Past and present lives of QR code and sorting out six test points
LeetCode 732. My schedule III
Attributeerror successfully resolved: can only use cat accessor with a ‘category‘ dtype
翻译生物医学说明书,英译中怎样效果佳
[mqtt from getting started to improving series | 01] quickly build an mqtt test environment from 0 to 1
How to convert flv file to MP4 file? A simple solution
Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
LeetCode - 152 乘积最大子数组
Monotonic stack
基于JEECG-BOOT的list页面的地址栏参数传递
It is necessary to understand these characteristics in translating subtitles of film and television dramas
Modify the list page on the basis of jeecg boot code generation (combined with customized components)
在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)
LeetCode 731. My schedule II
How effective is the Chinese-English translation of international economic and trade contracts
org. activiti. bpmn. exceptions. XMLException: cvc-complex-type. 2.4. a: Invalid content beginning with element 'outgoing' was found
如何做好金融文献翻译?