标签:style blog color io ar for sp div on
新题。。。不过很简单。。半年才更新一个题。。。
class Solution { public: int maxProduct(int arr[], int n) { int pmax = arr[0]; int pmin = arr[0]; int ans = arr[0]; for (int i = 1; i < n; i++) { int tmax = arr[i] * pmax; int tmin = arr[i] * pmin; pmax = max(arr[i], max(tmax, tmin)); pmin = min(arr[i], min(tmax, tmin)); ans = max(pmax, ans); } return ans; } };
[leetcode]Maximum Product Subarray
标签:style blog color io ar for sp div on
原文地址:http://www.cnblogs.com/x1957/p/3997892.html