```
class Solution {
public:
int maxProduct(int A[], int n) {
if (n==0) return 0;
int maxi = 1, mini = 1;
int out = INT_MIN;
for (int i=0;i<n;i++) {
int oldmaxi = max(maxi,1);
if (A[i] > 0) {
maxi = oldmaxi*A[i];
mini *= A[i];
} else {
maxi = mini*A[i];
mini = oldmaxi*A[i];
}
out = max(out,maxi);
}
return out;
}
};
```

Explanations could be found here:

http://changhaz.wordpress.com/2014/09/23/leetcode-maximum-product-subarray/