乘积最大子序列

代码:
class Solution {
public:
/**
* @param nums: a vector of integers
* @return: an integer
/
int maxProduct(vector& nums) {
// write your code here
int posMax = nums[0];
int negMax = nums[0];
int ret = nums[0];
for(int i=1;i<nums.size();i++)
{
int tempPosMax = posMax;
int tempNegMax = negMax;
posMax = max(nums[i],max(nums[i]
tempPosMax,nums[i]tempNegMax));
negMax = min(nums[i],min(nums[i]
tempPosMax,nums[i]*tempNegMax));
ret = max(ret,posMax);
}
return ret;
}
};

posted on 2017-08-17 23:02  p666  阅读(116)  评论(0编辑  收藏  举报

导航