当前位置:网站首页>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;
}
}
边栏推荐
- How to translate professional papers and write English abstracts better
- Chinese English comparison: you can do this Best of luck
- CS passed (cdn+ certificate) PowerShell online detailed version
- 查询字段个数
- University of Manchester | dda3c: collaborative distributed deep reinforcement learning in swarm agent systems
- Day 245/300 JS forEach 多层嵌套后数据无法更新到对象中
- Leetcode daily question (1997. first day where you have been in all the rooms)
- SQL Server manager studio(SSMS)安装教程
- LeetCode 731. My schedule II
- 论文翻译英译中,怎样做翻译效果好?
猜你喜欢

端午节快乐Wish Dragon Boat Festival is happy

Machine learning plant leaf recognition

Office doc add in - Online CS

MySQL5.72. MSI installation failed
![[unity] how to export FBX in untiy](/img/03/b7937a1ac1a677f52616186fb85ab3.jpg)
[unity] how to export FBX in untiy

How to convert flv file to MP4 file? A simple solution

CS certificate fingerprint modification

How to do a good job in financial literature translation?

Lecture 8: 1602 LCD (Guo Tianxiang)

The internationalization of domestic games is inseparable from professional translation companies
随机推荐
Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
Data type of MySQL
成功解决AttributeError: Can only use .cat accessor with a ‘category‘ dtype
Suspended else
A 27-year-old without a diploma, wants to work hard on self-study programming, and has the opportunity to become a programmer?
What are the commonly used English words and sentences about COVID-19?
mysql按照首字母排序
P5706 [deep foundation 2. Example 8] redistributing fat house water -- February 13, 2022
CS certificate fingerprint modification
国产游戏国际化离不开专业的翻译公司
Changes in the number of words in English papers translated into Chinese
[Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development
Use shortcut LNK online CS
商标翻译有什么特点,如何翻译?
SSO流程分析
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用Shap值对XGBoost模型实现可解释性案例之详细攻略
关于新冠疫情,常用的英文单词、语句有哪些?
英语论文翻译成中文字数变化
Basic knowledge of MySQL
Day 245/300 JS foreach data cannot be updated to the object after multi-layer nesting