题解 | #子数组最大乘积# PYTHON3 动态规划O(N)
子数组最大乘积
http://www.nowcoder.com/practice/9c158345c867466293fc413cff570356
# # # @param arr double浮点型一维数组 # @return double浮点型 # class Solution: def maxProduct(self , arr ): # write code here global_max = max(arr) neg_max = None pos_max = None for e in arr: a = pos_max * e if pos_max else e b = neg_max * e if neg_max else e global_max = max([a, b, global_max]) if e == 0: pos_max, neg_max= None, None else: pos_max = max([a, b]) if a > 1 or b > 1 else None neg_max = min([a, b]) if a < 1 or b < 1 else None return global_max