package com.fishercoder.solutions;

/**
 * 152. Maximum Product Subarray

 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 _152 {
  public static class Solution1 {
    public int maxProduct(int[] nums) {
      int pos = nums[0];
      int neg = nums[0];
      int max = nums[0];
      for (int i = 1; i < nums.length; i++) {
        int temp = pos;
        pos = Math.max(nums[i], nums[i] * ((nums[i] >= 0) ? pos : neg));
        neg = Math.min(nums[i], nums[i] * ((nums[i] >= 0) ? neg : temp));
        max = Math.max(max, pos);
      }
      return max;
    }
  }
}

@@ -33,263 +33,8 @@
 s;%0A%0A
-/**%0A * 152. Maximum Product Subarray%0A%0A Find the contiguous subarray within an array (containing at least one number) which has the largest product.%0A%0A For example, given the array %5B2,3,-2,4%5D,%0A the contiguous subarray %5B2,3%5D has the largest product = 6.%0A */%0A
 publ
@@ -49,16 +49,18 @@
  _152 %7B%0A
+  
   public
@@ -85,24 +85,28 @@
 tion1 %7B%0A    
+ 
+   
 public int m
@@ -131,24 +131,30 @@
 ms) %7B%0A      
+  
+    
 int pos = nu
@@ -152,32 +152,38 @@
  pos = nums%5B0%5D;%0A
+      
       int neg = 
@@ -187,24 +187,30 @@
  = nums%5B0%5D;%0A
+      
       int ma
@@ -228,16 +228,22 @@
 ;%0A      
+     
+ 
 for (int
@@ -270,24 +270,32 @@
 gth; i++) %7B%0A
+        
         int 
@@ -314,16 +314,24 @@
         
+ 
+       
 pos = Ma
@@ -395,16 +395,24 @@
         
+    
+    
 neg = Ma
@@ -477,16 +477,24 @@
         
+      
+  
 max = Ma
@@ -521,16 +521,28 @@
     
-%7D%0A
+      %7D%0A  
       
+    
 retu
@@ -553,16 +553,22 @@
 ax;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 152