题解 | #连续子数组的最大乘积#
连续子数组的最大乘积
https://www.nowcoder.com/practice/abbec6a3779940aab2cc564b22d36859
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param nums int整型一维数组
* @return int整型
*/
public int maxProduct (int[] nums) {
// write code here
int res = Integer.MIN_VALUE;
int dpMax = 1;
int dpMin = 1;
for(int i = 0;i<nums.length;i++){
int min = dpMin * nums[i];
int max = dpMax * nums[i];
dpMax = Math.max(max,Math.max(nums[i],min));
dpMin = Math.min(max,Math.min(nums[i],min));
res = Math.max(dpMax,res);
}
return res;
}
}