【leetcode】152. 乘积最大子数组
#define max(a,b) ((a)>(b))?(a):(b) #define min(a,b) ((a)<(b))?(a):(b) int maxProduct(int* nums, int numsSize){ int i, maxVal=nums[0], res=nums[0], minVal=nums[0], pre; for (i=1; i<numsSize; i++) { pre = maxVal; maxVal=max( nums[i],max(nums[i]*pre,nums[i]*minVal) ); minVal=min( nums[i], min(nums[i]*pre,nums[i]*minVal) ); res=max(res,maxVal); } return res; }