> 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.
解题思路:
暴力O(n^2)
超时
int maxProductN2(int A[], int n)
{
assert(A != NULL && n != 0);
if (n == 1) return A[0];
int result = A[0];
for(int i = 0; i < n; i++)
{
int t = 1;
for(int j = i; j >= 0; j--)
{
t *= A[j];
result = std::max(result, t);
}
}
return result;
}