标签:leetcode
https://oj.leetcode.com/problems/maximum-product-subarray/
http://blog.csdn.net/linhuanmars/article/details/39537283
public class Solution { public int maxProduct(int[] A) { if (A == null || A.length == 0) return 0; int localmin = 1; int localmax = 1; int global = Integer.MIN_VALUE; for (int i = 0 ; i < A.length ; i ++) { int copymax = localmax; localmax = max(localmax * A[i], localmin * A[i], A[i]); localmin = min(copymax * A[i], localmin * A[i], A[i]); global = Math.max(global, localmax); } return global; } private int min(int a, int b, int c) { return Math.min(a, Math.min(b, c)); } private int max(int a, int b, int c) { return Math.max(a, Math.max(b, c)); } }
[LeetCode]152 Maximum Product Subarray
标签:leetcode
原文地址:http://7371901.blog.51cto.com/7361901/1601206