当前位置:网站首页>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;
}
}
边栏推荐
- Summary of leetcode's dynamic programming 4
- 金融德语翻译,北京专业的翻译公司
- Simple query cost estimation
- Py06 字典 映射 字典嵌套 键不存在测试 键排序
- How much is the price for the seal of the certificate
- Day 245/300 JS foreach data cannot be updated to the object after multi-layer nesting
- Postman core function analysis - parameterization and test report
- Machine learning plant leaf recognition
- 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
- Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
猜你喜欢
Monotonic stack
Classification des verbes reconstruits grammaticalement - - English Rabbit Learning notes (2)
Financial German translation, a professional translation company in Beijing
翻译影视剧字幕,这些特点务必要了解
利用快捷方式-LNK-上线CS
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
Convert the array selected by El tree into an array object
Defense (greed), FBI tree (binary tree)
It is necessary to understand these characteristics in translating subtitles of film and television dramas
端午节快乐Wish Dragon Boat Festival is happy
随机推荐
Introduction and underlying analysis of regular expressions
Remember the implementation of a relatively complex addition, deletion and modification function based on jeecg-boot
Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
基于购买行为数据对超市顾客进行市场细分(RFM模型)
Distributed system basic (V) protocol (I)
Data type of MySQL
Summary of the post of "Web Test Engineer"
My seven years with NLP
Address bar parameter transmission of list page based on jeecg-boot
[ 英语 ] 语法重塑 之 英语学习的核心框架 —— 英语兔学习笔记(1)
In English translation of papers, how to do a good translation?
Successfully solved typeerror: data type 'category' not understood
Difference between backtracking and recursion
Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board
MySQL5.72. MSI installation failed
How much is it to translate Chinese into English for one minute?
Transfert des paramètres de la barre d'adresse de la page de liste basée sur jeecg - boot
Wish Dragon Boat Festival is happy
Apple has open source, but what about it?
电子书-CHM-上线CS