标签:min return tps 小数 cto col public ble http
problem:https://leetcode.com/problems/maximum-product-subarray
类似买卖股票,需要维护两个状态,当前最大数和最小数。
class Solution { public: int maxProduct(vector<int>& nums) { int res = INT_MIN; int num_max = 1; int num_min = 1; for(int i = 0;i<nums.size();i++) { int a = num_max * nums[i]; int b = num_min * nums[i]; num_max = max({a, b, nums[i]}); num_min = min({a, b, nums[i]}); res = max(res, num_max); } return res; } };
[动态规划] leetcode 152 Maximum Product Subarray
标签:min return tps 小数 cto col public ble http
原文地址:https://www.cnblogs.com/fish1996/p/11330291.html