当前位置:网站首页>LeetCode - 152 乘积最大子数组
LeetCode - 152 乘积最大子数组
2022-07-06 06:28:00 【三岁就很萌@D】

动态规划

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;
}
}
边栏推荐
- The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
- CS certificate fingerprint modification
- 記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
- Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board
- Black cat takes you to learn UFS Protocol Part 8: UFS initialization (boot operation)
- 生物医学英文合同翻译,关于词汇翻译的特点
- 电子书-CHM-上线CS
- A 27-year-old without a diploma, wants to work hard on self-study programming, and has the opportunity to become a programmer?
- mysql的基础命令
- LeetCode每日一题(971. Flip Binary Tree To Match Preorder Traversal)
猜你喜欢

JDBC requset corresponding content and function introduction

How to translate biomedical instructions in English

It is necessary to understand these characteristics in translating subtitles of film and television dramas

基于JEECG-BOOT的list页面的地址栏参数传递

Grouping convolution and DW convolution, residuals and inverted residuals, bottleneck and linearbottleneck

Lecture 8: 1602 LCD (Guo Tianxiang)

今日夏至 Today‘s summer solstice

org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容

Defense (greed), FBI tree (binary tree)

英语论文翻译成中文字数变化
随机推荐
SourceInsight Chinese garbled
Summary of the post of "Web Test Engineer"
[ 英语 ] 语法重塑 之 动词分类 —— 英语兔学习笔记(2)
模拟卷Leetcode【普通】1218. 最长定差子序列
Luogu p2089 roast chicken
It is necessary to understand these characteristics in translating subtitles of film and television dramas
Phishing & filename inversion & Office remote template
CS-证书指纹修改
如何做好金融文献翻译?
钓鱼&文件名反转&office远程模板
Simulation volume leetcode [general] 1062 Longest repeating substring
利用快捷方式-LNK-上线CS
Simulation volume leetcode [general] 1218 Longest definite difference subsequence
My daily learning records / learning methods
模拟卷Leetcode【普通】1143. 最长公共子序列
CS通过(CDN+证书)powershell上线详细版
How to convert flv file to MP4 file? A simple solution
Past and present lives of QR code and sorting out six test points
今日夏至 Today‘s summer solstice
mysql的基础命令