@@ -0,0 +1,1627 @@
+package coding4fun;%0A%0A/**%0A * Find the maximum product subarray.%0A *%0A * %3Cpre%3E%0A * Input: %5B-1, 2, -4, 3, -5%5D%0A * Output: 120%0A *%0A * Input: %5B-1, 2, 3, -4%5D%0A * Output: 24%0A *%0A * Input: %5B-3, -3%5D%0A * Output: 9%0A *%0A * Input: %5B5, -4, 2, 3%5D%0A * Output: 6%0A *%0A * Input: %5B1, -2, 3, -4, 5, -6%5D%0A * Output: 360%0A *%0A * Input: %5B1, -2, -3, 0, 7, -8, -2%5D%0A * Output: 112%0A * %3C/pre%3E%0A */%0Apublic class Problem43 %7B%0A    private static int maxProductSubArray(int%5B%5D array) %7B%0A        int max = 1;%0A        int minProduct = 1;%0A        int maxProduct = 1;%0A        for (int i = 0; i %3C array.length; i++) %7B%0A            if (array%5Bi%5D %3E 0) %7B%0A                minProduct = Math.min(minProduct * array%5Bi%5D, 1);%0A                maxProduct *= array%5Bi%5D;%0A            %7D else if (array%5Bi%5D == 0) %7B%0A                minProduct = 1;%0A                maxProduct = 1;%0A            %7D else %7B // array%5Bi%5D %3C 0%0A                int tmp = maxProduct;%0A                maxProduct = Math.max(minProduct * array%5Bi%5D, 1);%0A                minProduct = tmp * array%5Bi%5D;%0A            %7D%0A            max = Math.max(max, maxProduct);%0A        %7D%0A        return max;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(maxProductSubArray(new int%5B%5D%7B-1, 2, -4, 3, -5%7D)); // 120%0A        System.out.println(maxProductSubArray(new int%5B%5D%7B-1, 2, 3, -4%7D)); // 24%0A        System.out.println(maxProductSubArray(new int%5B%5D%7B-3, -3%7D)); // 9%0A        System.out.println(maxProductSubArray(new int%5B%5D%7B5, -4, 2, 3%7D)); // 6%0A        System.out.println(maxProductSubArray(new int%5B%5D%7B1, -2, 3, -4, 5, -6%7D)); // 360%0A        System.out.println(maxProductSubArray(new int%5B%5D%7B1, -2, -3, 0, 7, -8, -2%7D)); // 112%0A    %7D%0A%7D%0A

Add problem 43