leetcode5.18
Posted wfplingyun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode5.18相关的知识,希望对你有一定的参考价值。
152.乘积最大数组
include
using namespace std;
include
include
class Solution {
public:
int maxProduct(vector
int len = nums.size();
vector
vector
vmax.push_back(1);
vmin.push_back(1);
for (int i = 0; i < len; i++)
{
int tmp = nums[i];
if (tmp >= 0)
{
vmax.push_back( max(vmax[i] * nums[i], nums[i]));
vmin.push_back ( min(vmin[i] * nums[i], nums[i]));
}
else
{
vmax.push_back( max(vmin[i] * nums[i], nums[i]));
vmin.push_back(min(vmax[i] * nums[i], nums[i]));
}
}
int res = vmax[1];
for (int j = 1; j < len + 1; j++)
{
if (vmax[j] > res)res = vmax[j];
}
return res;
}
};
以上是关于leetcode5.18的主要内容,如果未能解决你的问题,请参考以下文章