动态规划

解题思路

1
2
3
4
5
6
7
8
9
def maxProduct(nums) -> int:
ret, ma, mi = float("-inf"), 1, 1
for num in nums:
if num < 0:
ma, mi = max(mi * num, num), min(ma * num, num)
else:
ma, mi = max(ma * num, num), min(mi * num, num)
ret = max(ret, ma)
return ret
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信