解答
代码实现如下:
class Solution { public:
int maxProduct(vector<int>& nums){
int n_size = nums.size();
if(!n size)return o; int dp_max = nums[0]; int dp_min = nums[@]; int max val = dp_max;
for (int i=1;i<n_size;i++) {
int tmp_max = dp_max;
dp_max = max(dp_max* nums[i], max(dp_min * nums[i], nums[i])); dp min = min tmp max * nums[i], min(dp min * nums[i], nums[i])); max val = max(max val, dp max);
returnn max_val;
};
帖子还没人回复快来抢沙发