当前位置:网站首页>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
边栏推荐
- VB.net类库——4给屏幕截图,裁剪
- 协同过滤进化版本NeuralCF及tensorflow2实现
- MATLAB and MySQL database connection and data exchange (based on ODBC)
- Background search, how to find the website background
- Y48. Chapter III kubernetes from introduction to mastery -- pod status and probe (21)
- VB.net类库,获取屏幕内鼠标下的颜色(进阶——3)
- 诗尼曼家居冲刺A股:年营收近12亿 红星美凯龙与居然之家是股东
- curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection
- Introduction of classic wide & deep model and implementation of tensorflow 2 code
- 关于appium踩坑 :Encountered internal error running command: Error: Cannot verify the signature of (已解决)
猜你喜欢

茂莱光学科创板上市:拟募资4亿 范一与范浩兄弟为实控人

VB.net类库,获取屏幕内鼠标下的颜色(进阶——3)

Vi/vim editor

Leetcode question brushing: String 05 (Sword finger offer 58 - ii. left rotation string)

财务费用分析怎么分析

Leetcode question brushing: String 02 (reverse string II)

基于启发式搜索的一字棋

API管理之利剑 -- Eolink

How to analyze financial expenses

MATLAB与Mysql数据库连接并数据交换(基于ODBC)
随机推荐
Application and Optimization Practice of 100 million level monthly live national karaoke feed service in Tencent cloud mongodb
How to enable Hana cloud service on SAP BTP platform
AI智能抠图工具--头发丝都可见
SAP commerce cloud project Spartacus getting started
Matrix calculator design for beginners of linear algebra based on Qt development
Leetcode: String 04 (reverse the words in the string)
The source code that everyone can understand (I) the overall architecture of ahooks
[protobuf] some pits brought by protobuf upgrade
How SAP Spartacus default routing configuration works
指南针能开户炒股吗?安全吗?
YuMinHong: New Oriental does not have a reversal of falling and turning over, destroying and rising again
Establish a connection with MySQL
网络连接断开请刷新重试
Dynamic parameter association using postman
2022年,中轻度游戏出海路在何方?
Usage of MGrid in numpy
Stop being a giant baby
360 mobile assistant is the first to access the app signature service system to help distribute privacy and security
Vi/vim editor
YOLOv6:又快又准的目標檢測框架開源啦