当前位置:网站首页>leetcode:152. Product maximum subarray [consider DP of two dimensions]
leetcode:152. Product maximum subarray [consider DP of two dimensions]
2022-06-26 21:42:00 【Review of the white speed Dragon King】

analysis
To find the subarray with the largest product
We use the maximum value that can be reached at present , The minimum value is enough
Concrete newmaxn = max(maxn * num, minn * minn, num)
newminn Empathy
Because it may be the smallest negative number multiplied by the current negative number is the smallest
So we can't simply solve it like the maximal sum of subarrays
Last record each maxn The maximum value of
ac code
class Solution:
def maxProduct(self, nums: List[int]) -> int:
# Maximum + The smallest array => Product maximum
maxn, minn, ans = 1, 1, -inf
for num in nums:
# Keep going
maxn1, minn1 = max(maxn * num, minn * num, num), min(maxn * num, minn * num, num)
maxn = maxn1
minn = minn1
ans = max(maxn, ans)
#print(minn, maxn)
return ans
summary
Record the maximum and minimum values at the same time dp
边栏推荐
- Is there any risk in opening a securities registration account? Is it safe?
- Convolutional neural network (CNN) explanation and tensorflow2 code implementation
- AI intelligent matting tool - hair can be seen
- Yonghui released the data of Lantern Festival: the sales of Tangyuan increased significantly, and several people's livelihood products increased by more than 150%
- Stop being a giant baby
- Is there any risk in registering and opening an account for stock speculation? Is it safe?
- Web crawler 2: crawl the user ID and home page address of Netease cloud music reviews
- 【题解】剑指 Offer 15. 二进制中1的个数(C语言)
- Treasure and niche cover PBR multi-channel mapping material website sharing
- YOLOv6:又快又准的目標檢測框架開源啦
猜你喜欢

leetcode刷题:字符串01(反转字符串)

经典Wide & Deep模型介绍及tensorflow 2代码实现

Sword finger offer 12 Path in matrix

Kdd2022 𞓜 unified session recommendation system based on knowledge enhancement prompt learning

模块五作业

Test comparison of linear model LN, single neural network SNN, deep neural network DNN and CNN

Dynamic parameter association using postman

记录一次Redis大Key的排查

【protobuf 】protobuf 昇級後帶來的一些坑

Gamefi active users, transaction volume, financing amount and new projects continue to decline. Can axie and stepn get rid of the death spiral? Where is the chain tour?
随机推荐
协同过滤进化版本NeuralCF及tensorflow2实现
DAST 黑盒漏洞扫描器 第五篇:漏洞扫描引擎与服务能力
【连载】说透运维监控系统01-监控系统概述
random_ normal_ Initializer uses
leetcode刷题:字符串05(剑指 Offer 58 - II. 左旋转字符串)
基于启发式搜索的一字棋
不同的子序列问题I
诗尼曼家居冲刺A股:年营收近12亿 红星美凯龙与居然之家是股东
经典Wide & Deep模型介绍及tensorflow 2代码实现
[Shandong University] information sharing for the first and second examinations of postgraduate entrance examination
聊聊我的远程工作体验 | 社区征文
[LeetCode]-链表-2
Introduction to dependency injection in SAP Spartacus
The source code that everyone can understand (I) the overall architecture of ahooks
Can compass open an account for stock trading? Is it safe?
VB.net类库,获取屏幕内鼠标下的颜色(进阶——3)
证券注册开户有没有什么风险?安全吗?
网络连接断开请刷新重试
Android mediacodec hard coded H264 file (four), ByteDance Android interview
花店橱窗布置【动态规划】