动态规划子数组系列一>乘积最大子数组
题目:
解析:
代码:
public int maxProduct(int[] nums) { int n = nums.length; int[] f = new int[n+1]; int[] g = new int[n+1]; f[0] = g[0] = 1; int ret = -0x3f3f3f3f; for(int i = 1; i <= n; i++){ int x = nums[i-1]; f[i] = Math.max(x,Math.max(g[i-1]*x,f[i-1]*x)); g[i] = Math.min(x,Math.min(g[i-1]*x,f[i-1]*x)); ret = Math.max(ret,f[i]); } return ret; }