LeetCode-Maximum Product Subarray

作者:disappearedgod
时间:2014-10-6

题目

Maximum Product Subarray

  Total Accepted: 4972  Total Submissions: 30676 My Submissions

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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-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]

想法

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

返回

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值