当前位置:网站首页>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;
}
}
边栏推荐
- (practice C language every day) reverse linked list II
- Biomedical English contract translation, characteristics of Vocabulary Translation
- Black cat takes you to learn UFS protocol Chapter 18: how UFS configures logical units (Lu Management)
- Phishing & filename inversion & Office remote template
- LeetCode每日一题(1997. First Day Where You Have Been in All the Rooms)
- Day 248/300 thoughts on how graduates find jobs
- Leetcode daily question (1997. first day where you have been in all the rooms)
- Lecture 8: 1602 LCD (Guo Tianxiang)
- Attributeerror successfully resolved: can only use cat accessor with a ‘category‘ dtype
- 自动化测试环境配置
猜你喜欢

Lecture 8: 1602 LCD (Guo Tianxiang)

如何做好金融文献翻译?

Postman core function analysis - parameterization and test report

Cobalt strike feature modification

论文摘要翻译,多语言纯人工翻译

基於JEECG-BOOT的list頁面的地址欄參數傳遞

Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board

Defense (greed), FBI tree (binary tree)

Market segmentation of supermarket customers based on purchase behavior data (RFM model)

How to do a good job in financial literature translation?
随机推荐
[mqtt from getting started to improving series | 01] quickly build an mqtt test environment from 0 to 1
红蓝对抗之流量加密(Openssl加密传输、MSF流量加密、CS修改profile进行流量加密)
基于JEECG-BOOT的list页面的地址栏参数传递
LeetCode 1200. Minimum absolute difference
Delete external table source data
MySQL high frequency interview 20 questions, necessary (important)
Day 245/300 JS foreach data cannot be updated to the object after multi-layer nesting
Cannot create poolableconnectionfactory (could not create connection to database server. error
钓鱼&文件名反转&office远程模板
CS-证书指纹修改
Black cat takes you to learn UFS protocol Chapter 18: how UFS configures logical units (Lu Management)
Redis core technology and basic architecture of actual combat: what does a key value database contain?
Advanced MySQL: Basics (1-4 Lectures)
Number of query fields
Biomedical localization translation services
生物医学英文合同翻译,关于词汇翻译的特点
论文摘要翻译,多语言纯人工翻译
[ 英语 ] 语法重塑 之 英语学习的核心框架 —— 英语兔学习笔记(1)
Lesson 7 tensorflow realizes convolutional neural network
How effective is the Chinese-English translation of international economic and trade contracts