###### Maximum Product Subarray

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.

class Solution {
public:
int maxProduct(vector<int>& nums) {
if(nums.empty())
return 0;
if(nums.size()==1)
return nums[0];
int max_temp = nums[0];
int min_temp = nums[0];
int max_value = nums[0];
for (int i = 1; i < nums.size(); i++)
{
int a = nums[i] * max_temp;
int b = nums[i] * min_temp;

max_temp = max( max(a,b) , nums[i]);
min_temp = min( min(a,b) , nums[i]);

max_value = max(max_temp,max_value);
}
return max_value;
}
};

#### [LeetCode] Maximum Product Subarray的4种解法

2014-09-26 12:11:40

#### LeetCode Maximum Product Subarray 解题报告

2014-10-06 12:09:35

#### Maximum Product Subarray -- LeetCode

2014-09-25 01:39:13

#### leetcode 152: Maximum Product Subarray

2014-12-30 09:18:02

#### LeetCode 53/152 Maximum Subarray/Maximum Product Subarray---DP **

2015-04-09 16:57:42

#### LeetCode - 152. Maximum Product Subarray - 思路详解 - C++

2017-01-16 19:26:41

#### [C++]LeetCode: 96 Maximum Product Subarray(动态规划)

2015-01-15 10:42:23

#### LeetCode 53/152 Maximum Subarray/Maximum Product Subarray（动态规划）

2018-01-04 11:19:00

#### Maximum Product Subarray：数组中最大连续区间求积

2017-10-09 09:06:26

#### 53. Maximum Subarray-动态规划/分治

2016-09-04 17:30:45

## 不良信息举报

Maximum Product Subarray