// Source : https://oj.leetcode.com/problems/maximum-product-subarray/ // Author : Hao Chen // Date : 2014-10-09 /********************************************************************************** * * Find the contiguous subarray within an array (containing at least one number) * which has the largest product. * * For example, given the array [2,3,-2,4], * the contiguous subarray [2,3] has the largest product = 6. * * More examples: * * Input: arr[] = {6, -3, -10, 0, 2} * Output: 180 // The subarray is {6, -3, -10} * * Input: arr[] = {-1, -3, -10, 0, 60} * Output: 60 // The subarray is {60} * * Input: arr[] = {-2, -3, 0, -2, -40} * Output: 80 // The subarray is {-2, -40} * **********************************************************************************/ #include #include using namespace std; int max(int x, int y) { return x>y?x:y; } int min(int x, int y){ return x