class Solution {
public:
int maxProduct(vector<int>& nums) {
if(!nums.size()) return 0;
vector<int>::iterator it=nums.begin();
int ma(*it),mi(*it),map,mip,ret(ma);
for(++it;it<nums.end();++it)
{
map=ma;
mip=mi;
mi=min(min(mip**it,map**it),*it);
ma=max(max(map**it,mip**it),*it);
ret=max(ma,ret);
}
return ret;
}
};
leetcode - 152. Maximum Product Subarray
最新推荐文章于 2022-03-25 16:53:26 发布