标签:target class pre rev tco subarray 链接 div ref
class Solution { public: int maxProduct(vector<int>& nums) { int len = nums.size(), res = nums[0]; int prevMin = nums[0], prevMax = nums[0]; int temp1 = 0, temp2 = 0; for (int i = 1; i < len; i++) { temp1 = prevMin * nums[i]; temp2 = prevMax * nums[i]; prevMin = min(min(temp1, temp2), nums[i]); prevMax = max(max(temp1, temp2), nums[i]); res = max(prevMax, res); } return res; } };
题目链接:https://leetcode-cn.com/problems/maximum-product-subarray/solution/
作者:hyj8
链接:https://leetcode-cn.com/problems/maximum-product-subarray/solution/wa-ni-zhe-ti-jie-shi-xie-gei-bu-hui-dai-ma-de-nu-p/
来源:力扣(LeetCode)
感谢!
标签:target class pre rev tco subarray 链接 div ref
原文地址:https://www.cnblogs.com/rtyxxy/p/12913117.html