package leetcode;

/**
 * https://leetcode.com/problems/maximum-product-subarray/
 */
public class Problem152 {
    public int maxProduct(int[] nums) {
        int answer = nums[0];
        int product = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (product * nums[i] == 0) {
                product = nums[i];
            } else {
                product *= nums[i];
            }
            int max = Math.max(nums[i], product);
            answer = Math.max(answer, max);
        }
        product = nums[nums.length - 1];
        for (int i = nums.length - 2; i >= 0; i--) {
            if (product * nums[i] == 0) {
                product = nums[i];
            } else {
                product *= nums[i];
            }
            int max = Math.max(nums[i], product);
            answer = Math.max(answer, max);
        }
        return answer;
    }
}

@@ -187,23 +187,46 @@
     int 
-product
+min = nums%5B0%5D;%0A        int max
  = nums%5B
@@ -294,488 +294,152 @@
    i
-f (product * nums%5Bi%5D == 0) %7B%0A                product = nums%5Bi%5D;%0A            %7D else %7B%0A                product *= nums%5Bi%5D;%0A            %7D%0A            int max = Math.max(nums%5Bi%5D, product);%0A            answer = Math.max(answer, max);%0A        %7D%0A        product = nums%5Bnums.length - 1%5D;%0A        for (int i = nums.length - 2; i %3E= 0; i--) %7B%0A            if (product * nums%5Bi%5D == 0) %7B%0A                product = nums%5Bi%5D;%0A            %7D else %7B%0A                product *= nums%5Bi%5D;%0A            %7D
+nt tmp = Math.max(nums%5Bi%5D, Math.max(nums%5Bi%5D * min, nums%5Bi%5D * max));%0A            min = Math.min(nums%5Bi%5D, Math.min(nums%5Bi%5D * min, nums%5Bi%5D * max));
 %0A   
@@ -451,44 +451,17 @@
     
-int 
 max = 
-Math.max(nums%5Bi%5D, product)
+tmp
 ;%0A  

Update problem 152