当前位置:网站首页>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;
}
}
边栏推荐
- Machine learning plant leaf recognition
- The internationalization of domestic games is inseparable from professional translation companies
- Mise en œuvre d’une fonction complexe d’ajout, de suppression et de modification basée sur jeecg - boot
- Leetcode daily question (1997. first day where you have been in all the rooms)
- LeetCode 1200. Minimum absolute difference
- Engineering organisms containing artificial metalloenzymes perform unnatural biosynthesis
- 论文摘要翻译,多语言纯人工翻译
- Apple has open source, but what about it?
- Py06 字典 映射 字典嵌套 键不存在测试 键排序
- Address bar parameter transmission of list page based on jeecg-boot
猜你喜欢

今日夏至 Today‘s summer solstice

Machine learning plant leaf recognition

基于购买行为数据对超市顾客进行市场细分(RFM模型)
![[unity] how to export FBX in untiy](/img/03/b7937a1ac1a677f52616186fb85ab3.jpg)
[unity] how to export FBX in untiy

Classification des verbes reconstruits grammaticalement - - English Rabbit Learning notes (2)

端午节快乐Wish Dragon Boat Festival is happy

mysql按照首字母排序

How to translate professional papers and write English abstracts better

翻译公司证件盖章的价格是多少

Oscp raven2 target penetration process
随机推荐
LeetCode每日一题(1997. First Day Where You Have Been in All the Rooms)
mysql按照首字母排序
[English] Grammar remodeling: the core framework of English Learning -- English rabbit learning notes (1)
Oscp raven2 target penetration process
Transfert des paramètres de la barre d'adresse de la page de liste basée sur jeecg - boot
Erreur de type résolue avec succès: type de données « catégorie» non sous - jacente
Wish Dragon Boat Festival is happy
Market segmentation of supermarket customers based on purchase behavior data (RFM model)
成功解决TypeError: data type ‘category‘ not understood
Traffic encryption of red blue confrontation (OpenSSL encrypted transmission, MSF traffic encryption, CS modifying profile for traffic encryption)
成功解决AttributeError: Can only use .cat accessor with a ‘category‘ dtype
端午节快乐Wish Dragon Boat Festival is happy
MySQL high frequency interview 20 questions, necessary (important)
(practice C language every day) reverse linked list II
云服务器 AccessKey 密钥泄露利用
LeetCode每日一题(971. Flip Binary Tree To Match Preorder Traversal)
Defense (greed), FBI tree (binary tree)
Drug disease association prediction based on multi-scale heterogeneous network topology information and multiple attributes
Day 246/300 ssh连接提示“REMOTE HOST IDENTIFICATION HAS CHANGED! ”
How to convert flv file to MP4 file? A simple solution