*
* @param arr double浮点型一维数组
* @return double浮点型
*/
function maxProduct( arr ) {
// write code here
//动态规划
let len = arr.length;
let res1 = new Array(len),res2 = new Array(len);
let max = arr[0];
res1[0] = arr[0],res2[0] = arr[0];
for(let i = 1;i < len;i++){
if(arr[i] > 0){
res1[i] = Math.max(arr[i],res1[i - 1] * arr[i]);
res2[i] = Math.min(arr[i],res2[i - 1] * arr[i]);
}else{
res1[i] = Math.max(arr[i],res2[i - 1] * arr[i]);
res2[i] = Math.min(arr[i],res1[i - 1] * arr[i]);
}
max = Math.max(max,res1[i])
}
return max;
}
module.exports = {
maxProduct : maxProduct
};