作者:disappearedgod
时间:2014-10-6
题目
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
.
解法
第一个想法是,这里可以用递归(依照于求子集(组合))
代码
public class Solution {
int max;
public int maxProduct(int[] A) {
max = Integer.MIN_VALUE;
if(A.length != 0)
combine(A, 0, 1);
return max;
}
void combine(int[] A, int index,int prod){
if(index == A.length){
return;
}
for(int i = index; i < A.length; ++i){
if(A[i] == 0){
findMax(0);
return;
}
prod *= A[i];
findMax(prod);
combine(A, i+1, prod);
prod /= A[i];
}
}
void findMax( int a){
max = max > a ? max : a;
}
}
结果
Runtime Error Message:Line 20: java.lang.StackOverflowErrorLast executed input:[-5,2,4,1,-2,2,-6,3,-1,-1,-1,-2,-3,5,1,-3,-4,2,-4,6,-1,5,-6,1,-1,-1,1,1,-1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,1,-1,-1,-1,-1,1,-1,1,-1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,-1,-1,1,-1,-1,-1,-1,1,1,1,1,1,1,-1,1,-1,1,-1,-1,1,-1,-1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,-1,1,1,-1,1,1,-1,-1,1,-1,1,-1,1,-1,-1,-1,-1,1,1,1,1,1,1,-1,1,1,-1,-1,1,1,1,-1,1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,1,-1,-1,1,1,-1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,-1,1,-1,1,-1,1,-1,-1,1,-1,-1,-1,-1,1,1,1,1,-1,1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,1,1,-1,-1,-1,1,-1,-1,-1,1,1,-1,1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1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-1,-1,1,-1,-1,-1,-1,-1,-1]
想法
Analysis:
similar like Maximum Subarray question
difference is the max value could be get from 3 situations
current maxValue * A[i] if A[i]>0
current minValue * A[i] if A[i]<0
A[i]
We need to record current maxValue, current minValue and update them every time get the new product
代码
public class Solution {
public int maxProduct(int[] A) {
if(A.length == 0)
return 0;
int ans = A[0];
int min = ans;
int max = ans;
for(int i = 1; i < A.length; ++i){
int cmp1 = A[i] * min;
int cmp2 = A[i] * max;
//+*-, -*-, 0
min = Math.min(A[i], Math.min(cmp1, cmp2));
max = Math.max(A[i], Math.max(cmp1, cmp2));
ans = Math.max(ans, max);
}
return ans;
}
}
结果
My Submissions for Maximum Product Subarray
Submit Time | Status | Run Time | Language |
---|---|---|---|
4 minutes ago | Accepted | 384 ms | java |