```
public class Solution {
public int maxProduct(int[] nums) {
int max=Integer.MIN_VALUE;
int currentP=1;
int currentN=1;
for(int i=0;i<nums.length;i++){
currentP*=nums[i];
if(currentP>max){
max=currentP;
}
if((currentP<0||currentN!=1)&&i+1<nums.length){
currentN*=nums[i+1];
if(currentN>max){
max= currentN;
}
}
if(currentP==0){
currentP=1;
}
else if (currentN==0){
currentN=1;
}
}
return max;
}
}
```