标签:style blog color io ar for sp div c
很久没练只能看别人代码了
1 class Solution { 2 public: 3 int maxProduct(int A[], int n) { 4 if (n == 0) return 0; 5 int curMax, curMin, ans; 6 ans = curMax = curMin = A[0]; 7 for (int i = 1; i < n; ++i) { 8 int tmp = curMin*A[i]; 9 curMin = min(A[i], min(tmp, curMax*A[i])); 10 curMax = max(A[i], max(tmp, curMax*A[i])); 11 ans = max(ans, curMax); 12 } 13 return ans; 14 } 15 };
LeetCode: Maximum Product Subarray
标签:style blog color io ar for sp div c
原文地址:http://www.cnblogs.com/yingzhongwen/p/4012148.html