题目描述:
方法一:动态规划
class Solution: def maxProduct(self, nums: List[int]) -> int: ret,up,down=nums[0],nums[0],nums[0] for n in nums[1:]: if n>=0: up,down=max(up*n,n),min(down*n,n) else: up,down=max(down*n,n),min(up*n,n) ret=max(ret,up) return ret
本文共 385 字,大约阅读时间需要 1 分钟。
题目描述:
方法一:动态规划
class Solution: def maxProduct(self, nums: List[int]) -> int: ret,up,down=nums[0],nums[0],nums[0] for n in nums[1:]: if n>=0: up,down=max(up*n,n),min(down*n,n) else: up,down=max(down*n,n),min(up*n,n) ret=max(ret,up) return ret
转载于:https://www.cnblogs.com/oldby/p/11203448.html