152. Maximum Product Subarray (1d-dp)
1. ๅ
ถๅฏฆๆ 0 ๆ ๅฅๆธๅneg ๆๆ่ฉฒ่ฆ้ๆฐ้ธๆ่ตทๅง้ป, ๆไปฅ่ฆ่ท nums[i] ๆฏ่ผ
2. ๅถๆธๅ neg ๆๅฏ่ฝๆ็ข็ max ๅผ, ่งฃๆณๆฏ็ด้ max ๅ min value, ๅฆๆneg*neg ๆๅฐฑๆ็ข็ max ๅผ
idea -
max( max product, min product, current value),
min( max product, min product, current value),
because of negative*negative may generate max number!
ๆๅพๅๆๅคงๅผ
time: O(n)
space: O(1)
original DP
then use variables, or like first one way
Last updated