标签:rod algo class name names solution pac size vector
152.乘积最大数组
using namespace std;
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;
}
};
标签:rod algo class name names solution pac size vector
原文地址:https://www.cnblogs.com/wfplingyun/p/12910054.html